Reputation: 13
I am trying to delete file from a folder which has 3,500 + files.
FolderA(3,500+Files), FolderB(<260 Files).
What I want is that I want a FolderA(3,500+Files) - FolderA(list.txt) = Missing files.
I have tried :
Get-Content c:\path\to\list.txt | Remove-Item
It doesn't work.
FolderA has over 3,500 files and within the folder i have a file called "list.txt" which has list of all files which I would like to delete from FolderA
Hope this make sense.
Thanks, Yogs
Upvotes: 0
Views: 617
Reputation: 70933
cd "C:\Users\gggggg\Desktop\missing2"
Get-Content "C:\Users\XXXXX\Desktop\missing2\ToBeDeleted.txt" | Remove-Item
Change active folder to the folder to be processed, get the list and remove each item
For a batch solution
for /f "delims=" %%a in ("C:\Users\XXXXX\Desktop\missing2\ToBeDeleted.txt") do (
del "C:\Users\gggggg\Desktop\missing2\%%a"
)
Upvotes: 0
Reputation: 80033
dir /b /a-d "FolderA*"|findstr /g:"FolderA\list.txt"
should do what you appear to want.
What has "FolderB" go to do with the problem?
--- er, you want to delete files that are not in the list list.txt
?
Well, the above should give you a list of files-to-be-deleted, so
for /f "delims=" %%a in ('dir /b /a-d "FolderA*"^|findstr /g:"FolderA\list.txt"') do ECHO(del "FolderA\%%a"
should echo
the same list. If it is correct, change the echo(del
to del
after verification to actually delete the files.
Upvotes: 0