Just want to ask, can you copy one entire directory to multiple destination?
Example
Source: "c:\MyProject\Sample\*.*"
Destination: "\\Computer1\Sample\"
"\\Computer2\Sample\"
"\\Computer3\Sample\"
"\\Computer4\Sample\"
I used this syntax to copy the entire directory
Example
Xcopy /E /Y "c:\MyProject\Sample*.*" "\Computer1\Sample\"
Now, Is there a way to loop through the following destination..? Do you have any suggestion on i can accomplish this scenario..?
Hope to hear from you soon..
Thanks,
Link
for %%D in (
"\\Computer1\Sample\"
"\\Computer2\Sample\"
"\\Computer3\Sample\"
"\\Computer4\Sample\"
) do Xcopy /E /Y "c:\MyProject\Sample*.*" "%%D"
The above assumes you are using a batch file. If run from the command line, then use %D instead of %%D. Also, the entire command can be put on one line, with spaces as path delimiters.
You can write a batch file that has multiple xcopies to achieve this
Xcopy /E /Y "c:\MyProject\Sample*.*" "\Computer1\Sample\"
Xcopy /E /Y "c:\MyProject\Sample*.*" "\Computer2\Sample\"
Xcopy /E /Y "c:\MyProject\Sample*.*" "\Computer3\Sample\"
Xcopy /E /Y "c:\MyProject\Sample*.*" "\Computer4\Sample\"
Related
I just try move all directories from directory "D:\Download" to "D:\DownloadArchive"
I try this but doesnt work
move /y "D:\Download\*.*" "D:\DownloadArchive"
Use "FOR /D" to select only directories. (Disclaimer: untested)
FOR /d %1 IN ("D:\Download\*") DO move /y "%1" "D:\DownloadArchive"
A very simple solution is to use a FOR statement to move each file in the directory. A better alternative to move is xcopy as it allows to over-wright existing files.
For the switches I'm using type xcopy /? in an CMD Window.
From Batch:
FOR /d %%i IN ("D:\Download\*") DO xcopy "%%i" "D:\DownloadArchive" /E /I /Y /S
From CMD:
FOR /d %i IN ("D:\Download\*") DO xcopy "%i" "D:\DownloadArchive" /E /I /Y /S
ok so I'm on Windows... hmm 7 still
I tried to find how to copy files from one directory to multiple, but I only found how to copy from various into one or one file only to various. I need to copy various file to various directories in function of the file name.
So I have this group of documents, I have a beautiful excel list which indicate for which document where I should send them so I tried a quick concatenate to have a batch file
The command line open well but it repeat the first line ad libitum
Can you explain to me where is my error ?
xcopy "C:\Users\me\Documents\Test\64340C-P3-4J01001A-PCS430033-01-Rev1.pdf" "C:\Users\me\Documents\Test\PE3-L-S04-00002" /z /i
xcopy "C:\Users\me\Documents\Test\64340C-P3-4J01001B-PCD430004-01-Rev1.pdf" "C:\Users\me\Documents\Test\PE3-L-S04-00013" /z /i
xcopy "C:\Users\me\Documents\Test\64340C-P3-4J01001B-PCD430004-03-Rev1.pdf" "C:\Users\me\Documents\Test\PE3-L-S04-00013" /z /i
xcopy "C:\Users\me\Documents\Test\64340C-P3-4J01001B-PCD430005-01-Rev1.pdf" "C:\Users\me\Documents\Test\PE3-L-S04-00013" /z /i
or
xcopy 64340C-P3-4J01001A-PCS430033-01-Rev1.pdf \PE3-L-S04-00002 /z /i
or
xcopy C:\Users\me\Documents\Test\64340C-P3-4J01001A-PCS430033-01-Rev1.pdf c:\Users\me\Documents\Test\PE3-L-S04-00002 /z /i
I have a batch command that will move certain files from one folder to another folder, as follows:
move /-y "U:\REVIT\REVIT FAMILES\*.00*.rfa" "U:\REVIT\Revit Backup Files"
pause
This moves the backup files that are created and have extensions of .001.rfa, .002.rfa etc. to another folder, but it only moves the files in that particular folder and does not move any from sub folders that exist as well. Could anyone please help with adding this function in?
Preserving the Directory Hierarchy
In case you want to preserve the directory hierarchy, you can do the following:
robocopy "U:\REVIT\REVIT FAMILES" "U:\REVIT\Revit Backup Files" "*.00*.rfa" /S /MOV /XC /XN /XO
The /XC /XN /XO options prevent from overwriting. Note that there is no prompt. Remove them to force overwriting already existing destination files.
Alternatively, you can use xcopy and del:
xcopy /Y /S /I "U:\REVIT\REVIT FAMILES\*.00*.rfa" "U:\REVIT\Revit Backup Files"
del /S "U:\REVIT\REVIT FAMILES\*.00*.rfa"
The /Y option forces to overwrite already existing destination files. When you change it to /-Y to achieve a prompt, del does not care about the selections and still deletes all of the matching source files.
Finally, a third option was to use a for loop:
set "TARGET=U:\REVIT\Revit Backup Files"
pushd "U:\REVIT\REVIT FAMILES"
for /F "tokens=2 delims=:" %%F in ('xcopy /L /S /Y /I "*.00*.rfa" "%TARGET%"') do (
2> nul md "%TARGET%\%%F\.."
move /-Y "%%F" "%TARGET%\%%F"
)
popd
The xcopy /L just lists the proposed files as paths relative to the source directory, but does not actually copy (due to /L). Every iterated file is moved by the move command; /-Y forces a prompt in case a destination file already exists. The md command is needed to create every sub-directory in the destination directory, 2> nul suppresses the error message in case one already exists.
Not Preserving the Directory Hierarchy
Again a for loop is needed, but this time dir /B /S replaces xcopy /L:
for /F "tokens=2 delims=:" %%F in ('dir /B /S /A:-D "U:\REVIT\REVIT FAMILES\*.00*.rfa"') do (
move /-Y "%%F" "U:\REVIT\Revit Backup Files\%%~nxF"
)
The ~nx modifier extracts the pure file name (base name plus extension) from the path in %%F.
I think you can achieve what you want with something like:
for /f %i in ('dir /s /b "REVIT FAMILES*.00*.rfa"') do move /-Y "%i" "U:\REVIT\Revit Backup Files\"
>%DT%.TXT 2>&1 (
xcopy E:\OUTSIDE\XFORM\%FN%.frm D:\OUTSIDE\XFORM /y
xcopy E:\OUTSIDE\XFORM\%FN%.fsl D:\OUTSIDE\XFORM /y
xcopy E:\OUTSIDE\XIMAGE\%FN%.img D:\OUTSIDE\XFORM /y
)
The code above is a sample of the lines I need redirected to a text file. This currently works with the exception that it only shows where the file is being copied from and how many files are being copied.
I need to be able to redirect the entire line so I can see where the files are being copied to as well for control purposes. Not entirely sure this is even possible via batch. Sadly it's my only option at this time.
I offer two simple batch solutions.
The first one is using parameter /F as suggested by MC ND:
>>%DT%.TXT 2>&1 (
xcopy E:\OUTSIDE\XFORM\%FN%.frm D:\OUTSIDE\XFORM /F /I /Y
xcopy E:\OUTSIDE\XFORM\%FN%.fsl D:\OUTSIDE\XFORM /F /I /Y
xcopy E:\OUTSIDE\XIMAGE\%FN%.img D:\OUTSIDE\XFORM /F /I /Y
)
The help of command xcopy can be read by running in a command prompt window xcopy /? which explains parameter /I as well - D:\OUTSIDE\XFORM should be interpreted as destination folder to be created automatically if not already existing.
The second one is echoing the source and destination before making the copy:
>>%DT%.TXT 2>&1 (
echo Copying E:\OUTSIDE\XFORM\%FN%.frm to D:\OUTSIDE\XFORM
xcopy E:\OUTSIDE\XFORM\%FN%.frm D:\OUTSIDE\XFORM /I /Y
echo Copying E:\OUTSIDE\XFORM\%FN%.fsl to D:\OUTSIDE\XFORM
xcopy E:\OUTSIDE\XFORM\%FN%.fsl D:\OUTSIDE\XFORM /I /Y
echo Copying E:\OUTSIDE\XFORM\%FN%.img to D:\OUTSIDE\XFORM
xcopy E:\OUTSIDE\XIMAGE\%FN%.img D:\OUTSIDE\XFORM /I /Y
)
I have checked some examples on internet but I can't get my (first) batch file to work. I would like to copy automatically my file from a folder to another one but nothing happen.
#echo off
xcopy "C:\source\" "C:\target\" /c /d /i /y
exit
Could you see anything wrong?
Thanks!!
Update: I have done the command given by Bali C but it still doesn't work. See snapshot
xcopy C:\folder1 C:\folder2\folder1 /t /e /i /y
xcopy C:\folder1 C:\folder2\ /t /e /i /y
Image:
I have to stop it with CTRL + C.
PS: I'm on Win 7
Update (Solution):
It works! The problem was the name xcopy,bat on my Desktop, and I was running the command from there, so it was executing the xcopy.bat file of my desktop instead of the Windows one.. I had to rename the file with "myxcopy.bat" :
#echo off
xcopy "C:\source" "C:\target" /c /d /i /y
exit
After testing most of the switches this worked for me:
xcopy C:\folder1 C:\folder2\folder1 /t /e /i /y
This will copy the folder folder1 into the folder folder2. So the directory tree would look like:
C:
Folder1
Folder2
Folder1
Based on xcopy help, I tried and found that following works perfectly for me (tried on Win 7)
xcopy C:\folder1 C:\folder2\folder1 /E /C /I /Q /G /H /R /K /Y /Z /J
If the requirement is to copy all files in "\Publish\Appfolder" into the parent "\Publish\" folder (inclusive of any subfolders, following works for me)
The switch '/s' allows copying of all subfolders, recursively.
xcopy src\main\Publish\Appfolder\*.* /s src\main\Publish\
You must specify your file in the copy:
xcopy C:\source\myfile.txt C:\target
Or if you want to copy all txt files for example
xcopy C:\source\*.txt C:\target