Reputation: 85
I'm trying to clean up a directory with a ton of files with windows powershell, and so far all the other StackOverflow posts haven't seemed to help me crack my issue.
I have a parent directory named /1/ I have a sub directory named /1/j/
I want to have all of the files in directory /1/ with (J) in any part of their names (including the parenthesis) moved into the /j/ sub directory. Example filename would be: "example filename (J).smc"
Here is the code I have so far that's not working:
$source = 'F:\1\'
$destination = 'F:\1\j'
Get-ChildItem $source -filter *.smc -recurse | Select-String -List -Pattern "(J)" | ForEach-Object {
Move-Item $PSItem.Path -Destination $destination
}
I feel like it's something simple, so I apologize if it is! Thanks for your help!!!
Upvotes: 1
Views: 816
Reputation: 85
Made it harder than it had to be. Thanks Olaf!
Solution:
Get-ChildItem -Path 'F:\1\' -Filter *'(j)'*.smc | Move-Item -Destination 'F:\1\j'
Upvotes: 3