Solved Is There a Better Way to Validate a Path?

Dell / DIMENSION 2400
February 2, 2012 at 03:30:50
Specs: MS-DOS 7.10, Pentium 4 / 1GB
I have this code to check the validity of a path:

  :: This checks if the drive and/or path does not exist
  ECHO Any junk text > JUNK1.TXT
  IF NOT EXIST %Image_To_Path%JUNK2.TXT                                GOTO ERRMSG22
  DEL %Image_To_Path%JUNK2.TXT > NUL

This seems like a lot of code, and I still get (possibly confusing) screen messages from the COPY command when the path is invalid (It says something about "path\JUNK2.TXT".).

See More: Is There a Better Way to Validate a Path?

Report •

February 2, 2012 at 06:59:31
IF EXIST "%Image_To_Path%" ECHO It's there.

How To Ask Questions The Smart Way

Report •

February 2, 2012 at 19:58:03
I tried that!

That works in the Command Prompt in Windows XP, though I could not find where this feature was documented in the on-screen help ("IF /?"). I need to do this from a boot floppy running MS-DOS 7.10. In my testing in real DOS it "usually" behaved like the following:

IF NOT EXIST "%Image_To_Path%" ECHO It's there.
IF EXIST "%Image_To_Path%" ECHO It's NOT there.

By "usually" I mean the results depended on what the path looked like (ie. Did it include a drive letter, a path, both, end in backslash?). I thought a directory was a special type of file, and so it should work, but no luck this way!

Report •

February 2, 2012 at 22:52:48
✔ Best Answer
In DOS i believe you can use nul to check the existence of a directory.

if exist s:\ome\path\nul echo echo s:\ome\path exists and is a directory

Report •

Related Solutions

February 5, 2012 at 00:44:40
Thanks, I tested every kind of path I could think of and got the expected results in MS-DOS. I haven't tested in PC DOS yet, but I expect it should be OK too.

Report •

Ask Question