PDA

View Full Version : xcopy


agithegreat
July 17th, 2007, 11:31 AM
Not exactly program related, was gonna put it in anything else but sorry.

Ok, here's the crack, i have a external harddrive and i want to compy multiple folders across at the click of a button. I have been using xcopy with this a command in a a shortcut for some time now. "%windir%\system32\cmd.exe /k xcopy D:\computer F:\*.* /s /e /r /v /k /f /h /y"
However where i have D:\Computer i would also like to include D:\work and a couple other folders, how would i go about this?
I know that i could just write out more shortcuts, but i'm sure there is a way to combine multiple folders into one command, so i dont have to click 3 shortcuts to move 3 folders.

Thanks for the help.

jtdoom
July 17th, 2007, 01:21 PM
hi

did you try a batch?

fixedchoice.cmd

%windir%\system32\cmd.exe /k xcopy D:\computer F:\computer /i /e /r /v /k /f /h /y /c
%windir%\system32\cmd.exe /k xcopy D:\work F:\work /i /e /r /v /k /f /h /y /c
%windir%\system32\cmd.exe /k xcopy D:\kids F:\kids /i /e /r /v /k /f /h /y /c

Note that I did put foldernames in F:\
so they would end up in separate folders...
/i will make it create subfolders if they do not exist, rather than ask..
/c will make it continue (if a file cannot be read, you will get an error report at the end.)
/s not needed if you use /E
Now, since you apparently wanted every file and subfolder of the chosen folder copied to the root of F:\drive, you can also do this
makechoice.cmd

@ECHO off
Echo copy contents of chosen folder to F:
echo.
echo drag folder into Dos-box
echo or, type a valid path to chosen folder, ie C:\DriverPacks
set /P CHOICE_1=
if not exist %CHOICE_1% goto nonvalid
cls
Echo on
%windir%\system32\cmd.exe /k xcopy %CHOICE_1% F:\ /e /r /v /k /f /h /y /c

oracle128
July 17th, 2007, 01:22 PM
That can't be done in XCopy. But why not just put the 3 commands into a batch file, then just run the batch file (or a shortcut to it)?

FYI your xcopy switches are redundant: /s and /e together do the same thing as /e by itself.

agithegreat
July 17th, 2007, 02:48 PM
Thankyou both, i learn more by the minute. So where i currently have a shortcut, that is the extent of my knowledge how do i go about making a batch file???
An yeh i want an exact clone, like D:/computer to go to F:/computer... ok???

So thanks anyway guys :)

EDIT: i did it, i googled how to batch :0 thaks a lot :)

jtdoom
July 17th, 2007, 07:05 PM
Thanks.
I wish I knew how to make a second choice for destination.

blabla..
set /P CHOICE_1=
if not exist %CHOICE_1% goto nonvalid
set /P MyBackup=
if not exist %MyBackup% goto nonvalid

xcopy %CHOICE_1% %MyBackup% /e /r /v /k /f /h /y /c

well, that did not work.. I can select source and destination, but it does not copy.

agithegreat
July 20th, 2007, 03:55 PM
Ok, i don't understand it. Lol sorry, i wrote this into notepad

"%windir%\system32\cmd.exe /k xcopy D:\computer F:\computer /i /e /r /v /k /f /h /y /c
%windir%\system32\cmd.exe /k xcopy D:\work F:\work /i /e /r /v /k /f /h /y /c
%windir%\system32\cmd.exe /k xcopy D:\downloaded F:\downloaded /i /e /r /v /k /f /h /y /c"

Then i renamed it as .bat from .txt.
It didnt do work or downloaded.... it only did computer. Why???

Thanks for the help.

oracle128
July 20th, 2007, 05:12 PM
Take out the "%windir%\system32\cmd.exe /k" from each line. Since a batch file runs from the command prompt already, you don't need to call cmd.exe each time.

agithegreat
July 20th, 2007, 05:20 PM
Thank you so much. It works, oh i love it when it does. lol

Is there a switch for xcopy thats the opposite to /y. So instead of automatically overwriting everything it only adds what was never there in the first instance???

As i will be adding to my F drive once a week but adding to the other files on a day to day basis.

jtdoom
July 20th, 2007, 10:21 PM
Hi
why did you add the quotes?

That was why it only did one folder.

agithegreat
July 21st, 2007, 09:54 AM
Sorry no i only quoted what i put into the batch file.
I didn't have the quotes in the batch itself.

oracle128
July 22nd, 2007, 06:33 AM
The opposite of /Y is /-Y, but it won't not overwrite existing files, it'll just prompt you to overwrite them (/Y only suppresses the prompting). xcopy doesn't have an option to only copy files that don't exist in the destination.