0

I've been having problems with xcopy in the past few days, and I'd like to stop ripping out my hair. In my DOS class, a portion of an assignment requires a file to be copied (with xcopy), and the new file name should have .bak appended, while keeping the original extension, but I can't get it to do this properly. Using xcopy * *.bak, I would expect it to do this, but it replaces the file extension, instead of appending. A friend of mine in the same class says this works as it should for him, which I do find strange. I've also tried other combinations of wildcards that Google results have suggested, but they give me the same results, and that's if I can find anything else relating to this.

I'd like to also expand, I'm not asking for homework help. My homework is easy, but I don't understand why xcopy would give me these results when the same command works for someone else. Thanks.

1 Answer 1

0

in DOS (and Windows command line) mask for all-files is *.*. Like in "files always have an extension, sometimes it's empty string". And filenames cannot end with .

So mask * canonically mean "files with empty extension". But some utilities, including xcopy as you found, automagically expand * to *.* because… well, I seek no logic when there isn't one. So * is shortcut for *.* in some cases.

Also, xcopy is apparently too smartass, and replaces extension even with

xcopy *.* *.*.bak

to add .bak extension, use plain copy with

copy * *.*.bak

(note that copy * *.bak will still replace extension)

or, if you required to use xcopy, write for-loop.

FOR %%I IN (*.*) DO xcopy %%I "%%~I.bak"

(in an interactive command line, use single percent-signs % instead of %%)

2
  • Hmm, thanks. I'm not required to use xcopy, but it's generally implied that we should be using what we went over in the course, including xcopy. Oh well. Copy is just fine, too. Apr 24, 2015 at 18:24
  • 1
    Yeah, no problem. Apr 24, 2015 at 18:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .