Copy folder to destination with its folder structure - batch-file

I have a folder foldertocopy with files in it. It is inside a folder structure like so
D:\somefolder1
|--somefolder2
|--somefolder3
|--foldertocopy
There could be other files or folders in any of the folders above. I have a destination folder like so E:\destinationfolder
I want to copy foldertocopy along with its contents to destinationfolder with the folder structure of foldertocopy till the parent somefolder2 so that at the end of copy it looks like so
E:\destinationfolder
|--somefolder2
|--somefolder3
|--foldertocopy
I don't want any of the other files or folders to get copied. How do I go about it?
I have tried robocopy in Windows 10, but I am not able to get the command right.
robocopy "D:\somefolder1\somefolder2\somefolder3\foldertocopy" "E:\destinationfolder" /E /LEV:3
All it does is, copy all the contents of foldertocopy to E:\destinationfolder, without any folder structure.

Related

Batch file to copy folder to multiple network destinations

I have been able to copy files from 1 location to another using the batch file.
However I need to copy the complete folder from one server to multiple servers.
Example;
Local machine name :
LOCAL
Destination machines :
Network1
Network2
folder that i need to copy
Local\d:\Hello
The whole folder hello and its contents to be copied
to
Network1\c
Network2\c
So the folders thats created should be like (with all the file within)
Network1\c:\Hello
Network2\c:\Hello
Looks like you might want to use xcopy. See below;
batch/bat to copy folder and content at once
You should end up with a script like this;
xcopy d:\Hello \\Network1\c$\ /E
xcopy d:\Hello \\Network2\c$\ /E

Need to copy and rename files in different folders

would anyone know how to write a batch file (or two) that would:
copy hundreds of "index.html" files that are in different folders and keep within the same folder (so needs to search within sub folders)
rename the copies (keep the originals as is) to "index.jpg"
could anyone help?
I used a bulk rename tool to rename all index.html files to index.jpg in a copy of the main folder, then used robocopy to copy everything over, including the file structure back to the original folder (leaving the index.html's alone)

How to exclude a specific file from being copied using xcopy

I'm new to Windows batch files, but I'm writing a .bat file that just copies a bunch of files from one place to another maintaining the file directory structure. Using xcopy this is simple but I need to exclude some files from being copied. You can use /exclude and create a text file full of strings that you want to be excluded, but this doesn't just exclude files with the exact names in the text file, it excludes all files whose filenames contain any of the strings in the text file.
What this means is, if I want to exclude any files named 123.txt and put this string in my exclusions text file, if there was a file called 1123.txt anywhere in the source folder or any of its subfolders that would also be excluded.
How can I exclude only files with a specific filename from being copied?
Evening Bill.
Can you add a slash before each file name? That should work
EG
instead of
123.txt
blah.txt
use
\123.txt
\blah.txt
Try creating a temporary folder, xcopying all of the files into that folder, deleting the ones you don't want, then xcopying those to the final destination. Finally, delete the temporary folder and its contents with rd xyzzy /q/s

seting up a template folder copy/ past system with batch

I have a foldering system setup consisting of a “master folder” wich varys in name holds two sub folders, the sub folders though are always called CTB and DWG. I want the contents. of the DWG folder always to be coppied to the desktop and the contents of the CTB to always be coppied to C:\ICT\Autocad_2010\CTB. Remembering that the master folder varys in name pending on the project.
Is this possible with batch?
somthing like:
XCOPY %0\DWG\*.* c:\ICT\AutoCAD_2010\CTB
Nevermind i got it
XCOPY "%cd%\DWG\*.DWG" c:\
however how do i copy it to the desktop?
try this to copy to the current user desktop
xcopy "dwg\*.dwg" "%Homedrive%%Homepath%\desktop"
or this to copy to all users desktop
xcopy "dwg\*.dwg" "%allusersprofile%\desktop"

Command Prompt and batch files

I'm trying to copy a number of files from a directory. I want to include the file path from the base of this particular directory tree, however, I only have a list of the file names to go by. Is there a way to copy either:
a list of files with their directories appended to the beginning in a .txt file
a copy of the folders in the directory with copies of the files placed in their original places in the original directory.
Each file in the directory has a unique name.
I've looked all over google, but the closest I've found is xcopy, which I don't believe is capable of this.
Thanks!
For the second option you can use xcopy /s or robocopy /s. Both are great tools for this kind of job.

Resources