I
I
imbacode2020-07-14 19:43:44
PowerShell
imbacode, 2020-07-14 19:43:44

Powershell how to delete many files with delete via pipeline?

There are several thousand folders with rum games in the current directory, in each of them, apart from a good dump of rum, there is a bunch of unnecessary ones, I actually wrote such a command so that only files ending in [!].nes remain

Get-ChildItem * -Recurse | Where-Object {$_.name -notmatch ".+[^W\]](\[\!\]\.nes)$"} | ForEach-Object { Remove-Item -LiteralPath $_.Name }


The first part (before ForEach-Object) works correctly, files are selected according to the template correctly, but only files in the first subdirectory in turn are deleted, in the second and following ones they are not deleted, that is, the task is such that only files that match the template remain in each subdirectory ( removed those that do not match). Tried with -match and copying to another folder - doesn't work either. What am I doing wrong? Help me please.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MaxKozlov, 2020-07-14
@imbacode

to delete instead of Name use FullName - name with full path

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question