Automate XCOPY help
Moderator: DosItHelp
-
- Posts: 3
- Joined: 09 Apr 2012 04:31
Automate XCOPY help
Hello Everyone,
I have created this batch command. Here i am copying the whole files and folders from a particular drive to newly created folder '_OLD' in the same drive. I want xcopy to start copying the folder and should wait until the first process is completed i.e. when it starts copying the files and folders of drive D:\ then it should not start the copying process for next drive until the process of drive D:\ is completed. I have used the command line /W but I have to do it manually i need a way to automate this. I hope someone has solution for this. Thank you in advance.
@echo off
md D:\_OLD
md E:\_OLD
md F:\_OLD
md G:\_OLD
xcopy "D:\*.*" D:\_OLD /Y /S /E /R /H /W
xcopy "E:\*.*" E:\_OLD /Y /S /E /R /H /W
xcopy "F:\*.*" F:\_OLD /Y /S /E /R /H /W
xcopy "G:\*.*" G:\_OLD /Y /S /E /R /H /W
cls
exit
I have created this batch command. Here i am copying the whole files and folders from a particular drive to newly created folder '_OLD' in the same drive. I want xcopy to start copying the folder and should wait until the first process is completed i.e. when it starts copying the files and folders of drive D:\ then it should not start the copying process for next drive until the process of drive D:\ is completed. I have used the command line /W but I have to do it manually i need a way to automate this. I hope someone has solution for this. Thank you in advance.
@echo off
md D:\_OLD
md E:\_OLD
md F:\_OLD
md G:\_OLD
xcopy "D:\*.*" D:\_OLD /Y /S /E /R /H /W
xcopy "E:\*.*" E:\_OLD /Y /S /E /R /H /W
xcopy "F:\*.*" F:\_OLD /Y /S /E /R /H /W
xcopy "G:\*.*" G:\_OLD /Y /S /E /R /H /W
cls
exit
Re: Automate XCOPY help
Try This:
It will start one copy process at atime and when done start the next the copy process will not be shown to see the files while copying remove "/Q" from the end of every xommand line
you can add more tasks after the last xcopy command as you like
Code: Select all
@echo off
cls
color 0c
For /D %%a IN (.) DO (
::==============================
Echo Copying Files In D:\_OLD
md md D:\_OLD
xcopy "D:\*.*" "D:\_OLD" /Y /E /R /H /Q
Echo Copying Files In E:\_OLD
md E:\_OLD
xcopy "E:\*.*" "E:\_OLD" /Y /E /R /H /Q
Echo Copying Files In F:\_OLD
md F:\_OLD
xcopy "F:\*.*" "F:\_OLD" /Y /E /R /H /Q
Echo Copying Files In G:\_OLD
md G:\_OLD
xcopy "G:\*.*" "G:\_OLD" /Y /E /R /H /Q
::==============================
color 0a
Echo Copying Process Finished
pause >nul
)
It will start one copy process at atime and when done start the next the copy process will not be shown to see the files while copying remove "/Q" from the end of every xommand line
you can add more tasks after the last xcopy command as you like
Re: Automate XCOPY help
This task is just made for a batch file and a loop! except you will get a recursive copy error I think. You can't copy a whole drive to a folder *on the same drive* using xcopy, without filtering out the target folder.
This is untested but it replicates the original batch file (with some extra switches):
If you really want to backup the whole drive to itself then reply and we can devise something. Why are you doing so anyway? It's a poor backup because if the drive fails then both copies are gone.
This is untested but it replicates the original batch file (with some extra switches):
Code: Select all
@echo off
for %%a in (d e f g) do (
md "%%a:\_OLD" 2>nul
xcopy "%%a:\*.*" "%%a:\_OLD\" /S /H /E /K /F /C /R /Y
)
cls
exit
If you really want to backup the whole drive to itself then reply and we can devise something. Why are you doing so anyway? It's a poor backup because if the drive fails then both copies are gone.
Re: Automate XCOPY help
The simple solution is to simply romove the /W option. You do not need the /W option to wait for the prior command to finish before beginning the next xcopy. The batch file will always wait for the prior command to finish.
The XCOPY /W option is intended to be used when the script is copying files to removable media and you want to give the user time to insert the media.
Dave Benham
The XCOPY /W option is intended to be used when the script is copying files to removable media and you want to give the user time to insert the media.
Dave Benham
-
- Posts: 3
- Joined: 09 Apr 2012 04:31
Re: Automate XCOPY help
Thank you all for your suggestions.
@foxidrive - Your code worked. This is not aimed to create a backup, it will be deleted eventually.
I am new to this so forgive me if i sound naive. Could it be possible instead of hard coding the drive names (d e f g), batch command automatically detects the number of drives and perform the copy process EXCEPT C:\?
@foxidrive - Your code worked. This is not aimed to create a backup, it will be deleted eventually.
I am new to this so forgive me if i sound naive. Could it be possible instead of hard coding the drive names (d e f g), batch command automatically detects the number of drives and perform the copy process EXCEPT C:\?
Re: Automate XCOPY help
Well you could in theory put all possible letters into the FOR LOOP and then before the xcopy you could just do and IF EXIST.
But I thought there was a way to pull the mounted devices from the registry or from another command. Memory is failing me this morning.
Code: Select all
@echo off
for %%a in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do (
IF EXIST %%a:\ (
md "%%a:\_OLD" 2>nul
xcopy "%%a:\*.*" "%%a:\_OLD\" /S /H /E /K /F /C /R /Y
)
)
cls
exit
But I thought there was a way to pull the mounted devices from the registry or from another command. Memory is failing me this morning.
Re: Automate XCOPY help
The registry does have a mounted devices key but it shows all mounted devices including any USB sticks that you previously mounted in the system. So in theory you will still have to check if they exist.
Another option is fsutil.
fsutil fsinfo drives
This shows all drive letters including any network drives. Which you probably don't want. I am assuming you just want local drives.
Another option is fsutil.
fsutil fsinfo drives
This shows all drive letters including any network drives. Which you probably don't want. I am assuming you just want local drives.
-
- Posts: 3
- Joined: 09 Apr 2012 04:31
Re: Automate XCOPY help
Thank you Squashman.
Could you also suggest how do I copy files or folders from a same location using Administrator privileges but the issue is user name between the path changes.
My PC is also being accessed by other users, I am the administrator and want to copy the logs from 'Document and Settings' of each users
Here are the Paths for example
C:\Documents and Settings\user1\Application Data\Pandion\Profiles
C:\Documents and Settings\user2\Application Data\Pandion\Profiles
C:\Documents and Settings\user3\Application Data\Pandion\Profiles
How do I write xcopy batch command so that it copy logs inside Profiles folder of each user and paste all into a master folder that I have specified?
Thank you in advance.
Could you also suggest how do I copy files or folders from a same location using Administrator privileges but the issue is user name between the path changes.
My PC is also being accessed by other users, I am the administrator and want to copy the logs from 'Document and Settings' of each users
Here are the Paths for example
C:\Documents and Settings\user1\Application Data\Pandion\Profiles
C:\Documents and Settings\user2\Application Data\Pandion\Profiles
C:\Documents and Settings\user3\Application Data\Pandion\Profiles
How do I write xcopy batch command so that it copy logs inside Profiles folder of each user and paste all into a master folder that I have specified?
Thank you in advance.
Re: Automate XCOPY help
"C:\Documents and Settings\user1" u can replace this with %userprofile%
this will always take u to the user profile folder
in windows xp u can replace the "C:\Documents and Settings\user3\Application Data\"
with %appdata% this will always take u to the application data folderand then complete the address like that %appdata%\Pandion\Profiles
this will always take u to the user profile folder
in windows xp u can replace the "C:\Documents and Settings\user3\Application Data\"
with %appdata% this will always take u to the application data folderand then complete the address like that %appdata%\Pandion\Profiles
Re: Automate XCOPY help
This is untested: If the folder exists for each user it should create a user folder and copy those *.log files over
Code: Select all
@echo off
for /f "delims=" %%a in ('dir "C:\Documents and Settings" /ad /b') do (
if exist "C:\Documents and Settings\%%a\Application Data\Pandion\Profiles\" (
md "z:\target folder\%%a" 2>nul
copy "C:\Documents and Settings\%%a\Application Data\Pandion\Profiles\*.log" "z:\target folder\%%a"
)
)