MS-DOS: XCOPY problem in batch file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Clueless in Seattle
Posts: 47
Joined: 01 Jul 2011 13:37

MS-DOS: XCOPY problem in batch file

#1 Post by Clueless in Seattle » 05 Jan 2014 10:39

Hi again! Anyone on board here who remembers the ins and outs of old-time MS-DOS batch file commands?

I'm trying to use a batch file to automate the process of copying a set of directory trees and their files from a floppy disk in drive A: over to RAM drive E: on my old laptop running MS-DOS 6.21.

I figure that the source of the problem is that I'm using the same name for both a file and a directory, like this:

Directory name: 0SUB-TST.DIR
File name: 0SUB-TST.TXT

When I manually enter the XCOPY command at the DOS prompt, DOS gives me back this query:

    Does 0SUB-TST.DIR specify a file name
    or directory name on target?
    (F = file, D = directory)?"


What I'm trying to figure out is how I could write a batch file that would answer that query with the equivalent of my pressing the "D" key on my keyboard.

I tried putting "<D" in the batch file at the end of the XCOPY command but that didn't work.

Here's what my non-working batch file looks like:

Code: Select all

:: TREECOPY.BAT: Copies test directory trees from A: to E:
::               for use with ENC-E2DX.BAT
::
@echo off
XCOPY A:\0SUB-TST.DIR E:\0SUB-TST.DIR /S /E /V
::
:: DOS returns query: "Does 0SUB-TST.DIR specify a file name
::                             or directory name on target?
::                             (F = file, D = directory)?"
::
XCOPY A:\0SUB-TST.DIR E:\0SUB-TST.DIR /S /E /V
XCOPY A:\1SUB-TST.DIR E:\1SUB-TST.DIR /S /E /V
XCOPY A:\2SUB-TST.DIR E:\2SUB-TST.DIR /S /E /V

:end

-----
Will in Seattle
a.k.a. "Clueless"

Squashman
Expert
Posts: 4471
Joined: 23 Dec 2011 13:59

Re: MS-DOS: XCOPY problem in batch file

#2 Post by Squashman » 05 Jan 2014 10:55

Isn't there a /I option?
Otherwise I would specify a backslash at the end of your paths.

Dos_Probie
Posts: 233
Joined: 21 Nov 2010 08:07
Location: At My Computer

Re: MS-DOS: XCOPY problem in batch file

#3 Post by Dos_Probie » 05 Jan 2014 11:11

Your dos version should support the /I switch which will make the "0SUB-TST.DIR" directory and not prompt you if file or directory or you could just do the MD command to make the directory..
DP 8)

penpen
Expert
Posts: 1995
Joined: 23 Jun 2013 06:15
Location: Germany

Re: MS-DOS: XCOPY problem in batch file

#4 Post by penpen » 05 Jan 2014 11:32

@Squashman, Dos_Probie: No, there is no /I option under his OS, and it shouldn't be there:
Clueless in Seattle wrote:(...) on my old laptop running MS-DOS 6.21. (...)

Code: Select all

C:\xcopy /?
Copies files (except hidden and system files) and directory trees.

XCOPY source [destination] [/A | /M] [/D:date] [/P] [/S [/E] [/V] [/W]
  source       Specifies the file(s) to copy.
  destination  Specifies the location and/or name of new files.
  /A           Copies files with the archive attribute set,
               doesn't change the attribute.
  /M           Copies files with the archive attribute set,
               turns off the archive attribute.
  /D:date      Copies files changed on or after the specified date.
  /P           Prompts you before creating each destination file.
  /S           Copies directories and subdirectories except empty ones.
  /E           Copies any subdirectories, even if empty.
  /V           Verifies each new file.
  /W           Prompts you to press a key before copying.
  /Y           Suppresses prompting to confirm you want to override an
               existing destination file.
  /-Y          Causes prompting to confirm you want to overwrite an
               existing destination file.

@Clueless in Seattle: Your problem could be solved using piping, but only if
you also use the /Y option (below), or
you ensure that you only xcopy new files;
else it hangs on waiting for any Y/N input for the question if it should overwrite this file:

Code: Select all

echo D|XCOPY A:\0SUB-TST.DIR E:\0SUB-TST.DIR /S /E /V /Y

penpen

Edit: Corrected my spelling (a little bit).
Last edited by penpen on 05 Jan 2014 11:44, edited 1 time in total.

Clueless in Seattle
Posts: 47
Joined: 01 Jul 2011 13:37

Re: MS-DOS: XCOPY problem in batch file

#5 Post by Clueless in Seattle » 05 Jan 2014 11:40

Squashman wrote:Isn't there a /I option?


No, this ancient version of MS-DOS doesn't seem to have an /I switch :(

Otherwise I would specify a backslash at the end of your paths.


Thanks, Squashman. It took me three tries, but I finally got that to work :)

First I added the backslashes to both the source and target paths like this:

Code: Select all

XCOPY A:\0SUB-TST.DIR\ E:\0SUB-TST.DIR\ /S /E /V


But all I got back was an "Invalid path" error message.

So I tried adding it just too the source path like this:

Code: Select all

XCOPY A:\0SUB-TST.DIR\ E:\0SUB-TST.DIR /S /E /V


But I still got the "Invalid path" error.

So I tried reversing it, and adding the backslash to just the target directory, like this:

XCOPY A:\0SUB-TST.DIR E:\0SUB-TST.DIR\ /S /E /V

And, bingo!. It worked.

Thanks for the help!

So now, do you have any ideas on why the backslash only works when added to the target path and produces an error when added to the source path? (Not that It really matters all that much, I guess. I mean, as long as I've got it working that's what counts. But still, it's often helpful to understand the underlying logic of these commands, isn't it?)
-----
Will in Seattle
a.k.a. "Clueless"

penpen
Expert
Posts: 1995
Joined: 23 Jun 2013 06:15
Location: Germany

Re: MS-DOS: XCOPY problem in batch file

#6 Post by penpen » 05 Jan 2014 11:53

Clueless in Seattle wrote:So now, do you have any ideas on why the backslash only works when added to the target path and produces an error when added to the source path?
Such a string "C:\SOME\PATH\" does not denote a filename, it is just a location.
The source parameter is defined to be (one or multiple) file(s),
while the destination should be a location/name.

penpen

Post Reply