Windows Batch: Copy child folders including files to different location - windows

The structure is like this:
c:\parent\level1\level2\
The level1 folder is empty
the level2 folder contains a lot of folders with files in it.
The goal is to copy all folders in level2 to a different folder, lets say c:\test but by keeping the original name of the folder:
c:\parent\level1\level2\folderwithfiles1\
c:\parent\level1\level2\folderwithfiles2\
The folderwithfiles1 and folderwithfiles2 need to be copied to a different location (including the files that are in those folders).
Now the challenge: the name of the level1, level2 and folderwithfilesX folder is variable (because these are automatically extracted folders).
I hope it's clear like this.

As best as I understand what you are trying to do isn't this just a case of robocopy /mir c:\parent\%l1%\%l2% c:\test which will take all files and subfolders of level2 and below and copy them to c:\test? You may prefer /e rather than /mir depending upon what is in c:\test.

Related

How to batch copy a list of folders and its file contents from a text file into a new folder in windows

I have a folder with approximately 7000 subfolders. I am interested in copying 1500 of those subfolders and their file contents into a new folder.
The closest I have got is copying the subfolders file contents into a new Target folder. However, the file contents are not copied over within their resepective subfolder making the batch copy useless to me.
Here is what I have tried.
CD E:\Source_Folder
FOR /F "delims=" %%N in (List.txt) do COPY "%%N" "Target_Folder"
I have tried XCOPY, ROBOCOPY, as well and all give me the same output of individual files in my target folder. I am looking for the subfolders with their contents to be copied into my new target folder.
Any help would be much appreciated. Thanks!
Just a try: rsync in linux does have the option to take the file-list to be synced from a file. Maybe robocopy (which is the windows-pendant) has the same capability, then you need one robocopy x y z only.
-edit: robocopy can'r read from a file, but if you search for 'robocopy reading from list' you get a lot of short scripts.

Robocopy - copy folders based on creation date

I'm trying to use robocopy to find all folders on a mapped drive and copy them based on the "folder" creation date. If I use /maxage it only looks for "files" age and not the folders, so it copies all folders and then files within the folders matching the /maxage setting.
Is there a /maxage setting for folders instead of files?
Thanks.

How to copy one folder into multiple folders in windows

This is the issue. I have a folder named Covers which is in another folder named Folder A. I have to copy the Covers folder from Folder A to all the sub-folders of another folder named Folder B. There are hundreds of sub-folders in Folder B. How can I do it through command line in windows or even power-shell.
Here is the folder structure:
Folder A
Folder B
Covers
Sub-Folder 1
Sub-Folder 2
Sub-Folder 3
Sub-Folder 4
The path of the FolderA is D:\AJ\Desktop\FolderA and the path of FolderB is D:\AJ\Desktop\FolderB.
I am trying to copy Covers folder from FolderA to all the sub-folders of FolderB.
This should do it. Use for /? to see the help for the command. /d means wildcards match directories, so it loops through the folders under FolderB and copies the files. xcopy /? will show that /sei will assume the destiniation is a directory and copy subdirectories including empty ones, to make sure everything under Covers gets copied. Use the cd command to start in the initial directory containing the folders:
cd /d d:\aj\desktop
for /d %i in (FolderB\*) do #xcopy "FolderA\Covers" "%i\Covers" /sei

Batch file to copy and rename files

I need a batch file that:
Copies all items (directories and subdirectories) from folder a to folder b
If I overwrite a file name/folder in folder a then it will correctly rename file/folder in folder b
I have accomplished the first task:
#echo off
xcopy "D:\...\abc\*.*" "D:\...\def" /E
pause
Above copies all the content in the folder to by destination folder i.e.
Folder a:
-folder1, folder2
-fileA, fileB
Is correctly present in folder b. However, if I rename a file in folder a and run the script:
rename folder1 -> folder0
Then this is how file structure looks:
Folder b:
-folder1, folder2, folder0
-fileA, fileB
I want folder1 to be renamed to folder0, how do I do this?
I could overwrite everything (not sure how with xcopy) but is there another solution to this?
I've looked at the various flags, but can't find what I'm after.
I think what you want it robocopy
You can mirror your folderA to folderB on execution of this batch file:
robocopy "D:\...\abc" "D:\...\def" /MIR /FFT /Z /XA:H /W:5
A great tutorial can be found here, explaining the various params

Need a batch file to copy new and changed files

I need to copy files from one location to another location, but only copy new files, or files that have changed.
For instance, I have data in C:\Working which includes folders and files. The files are changed, and removed from there as they are no longer needed or a project is complete.
I need a batch file to move everything in that location to D:\Storage. Since some files may not have changed, I do not want to copy those, however, I do want to copy and replace files that have been modified.
I believe I can use Robocopy /E and that will give me the recursion that I need. I am not sure on how to check hashes or stamps to verify if the file has been changed. I know I can EXCLUDE files with the /XC, but I think that's the opposite of what I want.
Right now my file as as folows:
#echo off
pushd C:\Working
>nul Robocopy /E . D:\Storage
popd
Edit: I don't want to just copy everything because the working location may have upwards of 60GB in it, and only 1-2GB needs to be copied.
http://ss64.com/nt/robocopy.html
By default Robocopy will only copy a file if the source and destination have different time stamps or different file sizes.
Therefore, Robocopy . D:\Storage /E should be fine. You may want to add the /XO option depending on what you want.

Resources