[Solved] Is There a Better Way to Validate a Path?

Score
0
Vote Up
February 2, 2012 at 03:30:50 Pacific
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
  COPY JUNK1.TXT %Image_To_Path%JUNK2.TXT > NUL
  DEL JUNK1.TXT > NUL
  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".).

Jump to Best Answer ↓   Report •


#1
Vote Down
Score
0
Vote Up
February 2, 2012 at 06:59:31 Pacific

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

How To Ask Questions The Smart Way


Reply ↓  Report •

#2
Vote Down
Score
0
Vote Up
February 2, 2012 at 19:58:03 Pacific

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!


Reply ↓  Report •

#3
Vote Down
Score
0
Vote Up
February 2, 2012 at 22:52:48 Pacific

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


Reply ↓  Report •

#4
Vote Down
Score
0
Vote Up
February 5, 2012 at 00:44:40 Pacific

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.

Reply ↓  Report •

Reply to Message Icon Start New Discussion
Related Posts

« Need a batch file to impo... vb script »