English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I try to make a super simple batch script to copy all files in a folder inside my Application Data to another folder there. But when I use my program it gives a syntax/path error. I am sure both paths are valid but maybe I have to use quote marks or something? Maybe it doesn't like that I want to copy the files to a not existing folder. It has to create a new folder and put the files in there.
This is what I made: (without "1st line:" and "2nd line:" of course)
1st line: @echo off
2nd line: xcopy %appdata%\source\*.* %appdata%\destination\ /s /e /-y

2007-03-31 11:12:16 · 6 answers · asked by Anonymous in Computers & Internet Programming & Design

6 answers

XCopy can definitely create your dirs and sub-dirs on the fly, so there's no need to do that prior to running your batch. However, I would recommend a couple of changes to the switches that you are using.

==== First, to address your most immediate issues,

1) Most importantly, as you've already guessed, since you're expanding the %appdata% environment variable, the spaces are not being parsed correctly. So you need to bracket your source and destination with quotes. If you don't, then DOS interprets the commandline as "xcopy c:\documents" with the remainder of the stuff being switches.

2) Also, if the /destination/ directory doesn't yet exist, then add the "/i" switch. This tells xcopy to assume that the destination is a directory if you're copying more than one file, and it will create the destination dir for you.

==== Second, some recommendations,

1) Add the "/h" switch, if you want to get hidden and system files, too.

2) Remove the "/s" switch. The "/e" which copies dirs and sub-dirs including empties, assumes the "/s"

3) Add the "/c" switch. This will make the xcopy command continue to additional files/dirs even if it hits an error. This way, you'll get most stuff, then be able to figure out why it's not getting the rest.

4) If you want to get all the stuff under \source\, and you're using the "/e" switch, then the *.* is not required.

5) If you're going to do this more than once, and you want to make sure to overwrite read-only files in your destination, then add the "/r" switch.

6) If you don't want to see the "overwrite <>? (Yes,No, All)" prompt every time you run your batch, then change your "/-y" to a "/y"


===========
So, your commandline should look like,

xcopy "%appdata%\source\" "%appdata%\destination\" /e /h /c /i /y /r

(All on one line, of course. Yahoo Answers wraps the line)

2007-04-01 02:07:40 · answer #1 · answered by Kevin 7 · 5 0

This Site Might Help You.

RE:
Batch script XCOPY command?
I try to make a super simple batch script to copy all files in a folder inside my Application Data to another folder there. But when I use my program it gives a syntax/path error. I am sure both paths are valid but maybe I have to use quote marks or something? Maybe it doesn't like that I want...

2015-08-19 02:49:40 · answer #2 · answered by Jeno 1 · 0 0

Hi, I only have three suggestions. 1. Add the trailing backslash, like this xcopy "c:\doc\fold\" 2. Or the path is simply too long. In which case, you might make it work by changing directory to the souce folder before the xcopy. It's Mickey-Mouse, but it might help. Or: It seems to me you just badly wrote the command switches forgetting the leading slash before the "S", so replace with /S /D /I /Y.

2016-03-15 07:36:25 · answer #3 · answered by Anonymous · 0 0

Xcopy Overwrite

2016-10-06 10:41:57 · answer #4 · answered by Anonymous · 0 0

DOS is simple minded. You have to create the directory yourself or create it in your batch file before the xcopy command using the "MD" command.

2007-03-31 11:17:47 · answer #5 · answered by pappy 5 · 2 1

For the best answers, search on this site https://shorturl.im/avCAR

xcopy works fine with relative file locations; if you put this on the flash drive as you ahve it shown, it should run without a problem.

2016-04-08 00:27:24 · answer #6 · answered by ? 4 · 0 0

How To Use Xcopy

2016-12-14 14:14:37 · answer #7 · answered by ? 4 · 0 0

i don't think you can copy whole folders in batch.

2007-03-31 11:17:53 · answer #8 · answered by SRP333 2 · 0 2

Use mkdir to create the folders before do the xcopy.

2007-03-31 14:51:16 · answer #9 · answered by Buck Boy 2 · 0 1

fedest.com, questions and answers