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
Related
for /r "C:\Users\bui\Desktop\Annotation Traing Package\test1" %i in (*03.json) do copy "%i" "C:\Users\bui\Desktop\Annotation Traing Package\test2"
i want to copy all 03.json files from test1 to test2 but in test1 folder, there are subfolders, and in those subfolders also have 03.json files. With for loop i cant loop through subfolders and copy 03.json files in it, but i also want to copy those subfolders from test1 to test2 with those 03.jon files in it. is there possible way to do it?
i tried using xcopy to copy those subfolders first then use for loop but no use, bc they copy all files to "C:\Users\bui\Desktop\Annotation Traing Package\test2"
RoBoCopy is the best method to do this IMHO.
Robocopy "C:\Users\bui\Desktop\Annotation Traing Package\test1" "C:\Users\bui\Desktop\Annotation Traing Package\test2" *03.json /E /S /B
The Robocopy utility is made to copy directory trees and matching files and has been included in windows since Windows 7 released in 2009.
Note I used /E assuming you would want the folders which are empty assuming you may have things like log folders which contain no "03.json" files
If you do not want to create empty directories when they do not contain "03.json" files, then simply omit the /E option
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
I am trying to copy files from folder1 to folder2 but exclude few files. lets say
Source dir: D:\test1
Dest dir: D:\test2
Source dir has files: hello1.txt, hello2.txt, hello3.pdf.....(and so on with different extension)
My batch cmd: Xcopy /Y /exclude:D:\test1\Excludefiles.txt D:\test1 D:\test2
I have added list of files in Excludefiles.txt that I dont want to copy.
The issue is everything works fine except Excludefiles.txt gets copied in dest folder too which I dont want. How can I exclude Excludefiles.txt getting copied?
I have a batch script which moves all the files from one folder to another and then renames them all to .jpg, however my .bat file itself gets renamed in the process because it sits in the destination folder. I need to exclude it from getting renamed.
Also, does the ren command exclude items in subfolders by default? I only want items in the destination folder renamed, not items in its subfolders.
#echo off
xcopy "C:\Folder1" "C:\Folder2"
cd "C:\Folder2" && ren *.* *.jpg
pause
I want to create a batch file that moves all the files in this directory to its father directory. Like for example if I have a directory " Something " that contains files :
...New Folder/Something
And I want to move the files in " Something " to New folder.
Is there such a command?
Thanks a bunch :)
Presuming you're talking about Windows batch files, move *.* ..\ should do the trick.
Edit: For example, if you opened cmd, you could input:
cd C:\New Folder\Something
move *.* ..\
which would move all files in C:\New Folder\Something into its 'father' directory.
It is possible only if you don't have subdirectories, because move doesn't walk the subdirectories.
You can use xcopy with /E, however it will not delete the copied files and directories. Then you should use del ., but to delete the subdirectories you should call rd for each one, and that is not possible in batch files.