I recently got a new laptop, and for some reason DropBox decided to duplicate everything. I like to learn a little bit of PoSH often, so I can be more proficient at it, so I decided that it might be a good time, but still Iβm out of luck. I'm not a complete noob, but definitely still a bit.
Basically, all dupe files have (1) at the end (for example, the file name is (1) .txt). I was able to pinpoint those who:
gci -recurse | ? { $_.Name -like "*(1)*" }
So far, good, but then I want to move them to the "dupes" directory and keep the subfolder structure. For some reason, it seems like it should be simple, PoSH makes it super complex. I searched high and low and found some close examples, but they also include many other parameters that just confuse me. I believe that I am behind this:
* Find items with the specified command
* Pipe to Move-Item
* Somehow include a new element-Directory name -force
* Also make sure this directory does not exist yet
I currently have:
$from = "C:\users\xxx\Dropbox" $to = "C:\Users\xxx\Downloads\DropBox Dupes" gci | ? { $_.Name -like "*(1)*" } | New-Item -ItemType Directory -Path $to -Force Move-Item $from $to -Force
Any pointers / help / examples?
Thanks!
Ps Although I stopped dropbox and tried several different files, currently I get:
Move-Item : Cannot move item because the item at 'C:\users\jkelly.MC\Dropbox' is in use. At line:2 char:1 + Move-Item $from $to -Force + ~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [Move-Item], PSInvalidOperationException + FullyQualifiedErrorId : InvalidOperation,Microsoft.PowerShell.Commands.MoveItemCommand