1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Verify validity of file name and/or path...

Discussion in 'Suggestions' started by mathewsdw, Dec 7, 2012.

  1. mathewsdw

    Joined:
    May 24, 2010
    Messages:
    855
    Likes Received:
    0
    While I've got code I've been using for a long time ("%@ExecStr" a batch file), it would be really nice if in addition to "Exist", "IsFile", and "IsDir", there was an "IsPath" (for instance), which would be true if the given path is valid. In the case of the rightmost component of the path, just verify that the name is acceptable ("St*r", for instance, would fail the test) and for the rest of the path (everything preceding the rightmost component and separated from the rightmost component by a back slash) that the drive (if specified) and all of the leftmost components of the path are valid, exist, and are directories.

    Just for reference, the existing batch file echos:
    3 For a valid device (CON:, LPT1:, COM2, NUL:, etc.)
    2 For an existing directory
    1 For an existing file
    0 For a valid name that does not exist
    -1 For a high-order component that is not a valid path (not all components exist and are directories.
    -2 For an invalid (syntax) path/name
    -999 For something that exists but is not a file, a directory, or a device
    (Should really never happen)

    This, of course, wraps all of the tests into one value.
     
  2. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,952
    Likes Received:
    30
    A path minus the filename is a directory. How about:
    Code:
    if isdir %@path[...]
     
  3. mathewsdw

    Joined:
    May 24, 2010
    Messages:
    855
    Likes Received:
    0
    Thank you Vince, I was already doing that (I guess I really didn't make that clear because I was describing what it did, not how it did it, which in truth I didn't even remember the details of because it was written years ago and I didn't really spend any time looking at the code - it was just a very old "building block" that I use pretty much without thinking about it.) But I'll note that that's only a relatively small part of the complete task.
     

Share This Page