Zoom7000 Posted May 26, 2013 Posted May 26, 2013 Can someone help me write a quick script to copy files from 1 location to another? I have files in this folder structure: C:\Other Files\Misc\\ I want to copy all the .doc files from the folder to the following location: E:\Other Files\Misc Can someone help me with a script that will do it for me? Thanks in advance!
noxigen Posted May 26, 2013 Posted May 26, 2013 You could create a simple batch file to do this. Just save the following command to CopyFiles.bat (or whatever you want to call it): xcopy /s "C:\Other Files\Misc\*.doc " "E:\Other Files\Misc\*.*" This will copy all .doc files and retain the original folder structure as well.
FishCustard Posted May 26, 2013 Posted May 26, 2013 Something like... robocopy *.doc /e ...should do it.
Zoom7000 Posted May 26, 2013 Author Posted May 26, 2013 You could create a simple batch file to do this. Just save the following command to CopyFiles.bat (or whatever you want to call it): xcopy /s "C:\Other Files\Misc\*.doc " "E:\Other Files\Misc\*.*" This will copy all .doc files and retain the original folder structure as well. No, that won't work, you've missed out a level in the folder structure: C:\Other Files\Misc\\*.doc How do I declare the in the script?
old_n07 Posted May 26, 2013 Posted May 26, 2013 This PS script should do it $source = "C:\Other Files\Misc" #source directory $dest = "E:\Other Files\Misc" #destination directory (must exist) #search source directory and subfolders for .doc files $files = get-childitem $source -recurse -Include *.doc | select-object DirectoryName,Name #copy files to destination foreach ($file in $files) { $item = $file.Directoryname + "\" + $file.name Copy-Item $item -Destination $dest}
old_n07 Posted May 28, 2013 Posted May 28, 2013 I've edited the code above included a line to check for the destination folder and create if it doesn't exist $source = "C:\Other Files\Misc" #source directory $dest = "E:\Other Files\Misc" #destination directory #search source directory and subfolders for .doc files $files = get-childitem $source -recurse -Include *.doc | select-object DirectoryName,Name #check for destination folder and create if doesn't exist If(!(Test-Path $dest)) {new-item $dest -type directory} #copy files to destination foreach ($file in $files) { $item = $file.Directoryname + "\" + $file.name Copy-Item $item -Destination $dest}
mattx Posted May 28, 2013 Posted May 28, 2013 No, that won't work, you've missed out a level in the folder structure: C:\Other Files\Misc\\*.doc How do I declare the in the script? Errrrrrrr *.* /s /e /h ? If it's just a one off, back it up using some backup software and then restore to the new location.
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