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
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
#echo on
cls
set "root"="%CD%"
cd bin\cemu*
xcopy /q .\mlc01\* "%root%\temp\mlc01\" /e /i /y
xcopy /q .\hfiomlc01\* "%root%\temp\hfiomlc01\" /e /i /y
cd ..
rmdir /s /q cemu_1.7.3d
rmdir /s /q cemu_1.7.4d
cd ..
cd bin\cemu*
xcopy /q "%root%\temp\" .\mlc01\* /e /i /y
xcopy /q "%root%\temp\" .\hfiomlc01\* /e /i /y
cd "%root%"
pause
everything works fine with changing directories and everything but xcopy isn't copying directories or anything (I used this same command in my other project to and it works fine but here it wont)
I tried /s /t /e and all that stuff and I still cant get it going
Try changing:
set "root"="%CD%"
to:
set "root=%CD%"
Due to the quirks that exist in cmd.exe's quoting (cmd.exe has so many quirks) the first variation doesn't do what you want it it to do - it creates an environment variable named root" (yes, the environment variable name has a trailing double-quote character).
I want to copy folder IMAGE to all other folders in a folder.
The folder structure is:
Test folder
FirstSubFolder
IMAGE
OneMoreSubFolder
Test Folder 1
TestFolder2
The result should be:
Test folder
FirstSubFolder
IMAGE
IMAGE
OneMoreSubFolder
IMAGE
Test Folder 1
IMAGE
TestFolder2
IMAGE
Which commands do I need in a batch script to do this folder copying task?
With Test folder being the current directory use following batch code:
#echo off
for /D %%D in (*) do (
if /I not "%%D" == "IMAGE" (
xcopy "IMAGE\*" "%%D\IMAGE\" /C /E /H /I /K /Q /R /Y >nul
)
)
Or if just the files and subfolders in IMAGE should be copied to all other subfolders of Test folder, use this code:
#echo off
for /D %%D in (*) do (
if /I not "%%D" == "IMAGE" (
xcopy "IMAGE\*" "%%D\" /C /E /H /I /K /Q /R /Y >nul
)
)
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
echo /?
for /?
if /?
xcopy /?
Im trying to copy files from one drive to another using a batch file, Which works! but we keep Changing file names on our main file which creates addition copys with diffrent names everytime its run. I dont want to delete the Copy file entirely bacause of the length of time the copy takes just to copy. I would like to Compare the 2 files and delete the files that are no longer on the main drive here is the test that im working on. Thanks for any help you can give me.
#echo
cls
If not exist "C:\Users\Jeremy\Desktop\Test Main\*.*" "Del "C:\Users\Jeremy\Desktop\Test Clone\*.*"
xcopy "C:\Users\Jeremy\Desktop\Test Main\*.*" "C:\Users\Jeremy\Desktop\Test Clone\*.*" /D /C /E /S /I /Y /V /H /R /F /d:01-01-1998
pause
:abort
echo You pressed CTRL+C to end the copy operation.
goto exit
you might want to look into robocopy, specifically with the /mir switch, which mirrors (copy all new files and delete all no longer existing files) the source folder to the target.
Thanks
This does work
#echo
cls
robocopy /MIR "C:\Users\Jeremy\Desktop\Test Main" "C:\Users\Jeremy\Desktop\Test Clone"
pause
:abort
echo You pressed CTRL+C to end the copy operation.
goto exit
But I would still like to understand if anyone can or wants to take the time to correct my original question
Try:
#echo off
cls
If not exist "C:\Users\Jeremy\Desktop\Test Main\*.*" "Del "C:\Users\Jeremy\Desktop\Test Clone\*.*"
xcopy "C:\Users\Jeremy\Desktop\Test Main\*.*" "C:\Users\Jeremy\Desktop\Test Clone\*.*" /D /C /E /S /I /Y /V /H /R /F /d:01-01-1998
If %errorlevel% EQU 2 (
echo You pressed CTRL+C to end the copy operation.
)
pause
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\"