Click here to Skip to main content
15,888,218 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have some folder containing many files. I want to check whether the file exists in those folders. If the file exists in some folder, it means I a have duplicate file in the folder. The duplicate file is not fully the same name, but I can identify from part of the file name. Once I identify the file name, I will remove one of them.

I tried this, I can identify which folder contains the file that I want. But I do not know how to remove it

What I have tried:

$FindJobpros = Get-ChildItem -Name "$OpJob_Path\*\*.pro\"
    ForEach ($FindJobpro in $FindJobpros)
    {
        $SubFile = $FindJobpros.Substring(7, 35)
        $GetDupFile = Get-ChildItem -Path $OpJob_Path\*\*.que | Where-Object {$_.Name -Match "$SubFile"}
        Remove-Item $GetDupFile
    }

}
Posted
Updated 19-Aug-19 6:11am

1 solution

Maybe you should add
-Confirm:$false
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900