gtg93 Posted October 28, 2014 Posted October 28, 2014 We need a way of copying all files from multiple folders that share parts of the same name into a new directory, for example: We have 3 folders called 123folder folder832 and xfolder45 and we want all items to be moved into "folder". In the original directory, there are 600 folders, and they need brining down to 300/400 folders by merging folders with similar filenames as per my example. This is to move a mess of users home directories, onto a new server from a site we've just taken over. For some reason there are two or three folders for some users. We've tried xcopy "C:\*folder*\*.*" "C:\folder" but this doesn't work. Also, we've tried FOR /d %a in (folder*) DO XCOPY "C:\%a" "C:\%a\" /s /e /f /h /k /y with no luck. Hopefully this makes sense... If anyone has a script or can link to some info or some software that can do what we require it'll be appreciated. Cheers
gtg93 Posted October 29, 2014 Author Posted October 29, 2014 Quick bump to bring this back to front page since I posted it quite late last night - any helps appreciated.
unixman_again Posted October 29, 2014 Posted October 29, 2014 You can probably do it with Bulk Rename Utility Among it's many options is move files and rename as they are moved. 1
jamesb Posted October 29, 2014 Posted October 29, 2014 (edited) I'm fairly sure this could be done with a simple PowerShell script. Something like this. $commonName = "folder" $targetPath = "C:\$commonName" foreach ($ci in Get-ChildItem -Path C:\ -Recurse -Directory) { if ($ci.Name -like "*$commonName*") { Get-ChildItem $ci | Move-Item $targetPath } } That'll match anything with "folder" in the directory name, and move its contents to the target "C:\folder". If you want it to work with more matches than just folder create an array for the keywords, and wrap it in a foreach loop. You might also want to focus the initial search path a little more than just on the root. Edited October 29, 2014 by jamesb 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now