home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cenvi23.zip / VALIDDIR.CMD < prev    next >
OS/2 REXX Batch file  |  1994-10-04  |  2KB  |  53 lines

  1. EXTPROC CEnvi2
  2. /**************************************************************************
  3.  *** ValidDir.cmd   Check if the specified directory is valid.  Return  ***
  4.  *** ver.1          errorlevel 0 if it's OK, else ERRORLEVEL 1.  If two ***
  5.  ***                parameters are given then print error if problem.   ***
  6.  **************************************************************************/
  7.  
  8. main(argc,argv)
  9. {
  10.    RetCode = 1; // assume failure
  11.    if ( 1 == argc  ||  !strcmpi(argv[1],"/?")  ||  !stricmp(argv[1],"/help") ) {
  12.       Instructions();
  13.    } else {
  14.       RetCode = ( ValidSubDirectoryName(argv[1],argc==3) ) ? 0 : 1 ;
  15.    }
  16.    return( RetCode );
  17. }
  18.  
  19. ValidSubDirectoryName(DirName,PrintMessageIfInvalid)
  20.    // test if DirName is a valid directory name.  If it is then return TRUE, else
  21.    // print message if PrintMessageIfInvalid is True and return FALSE.  This function
  22.    // reports the root directory as being invalid.
  23. {
  24.    DirIsValid = FALSE; // assume failure
  25.    FullDirName = FullPath(DirName);
  26.    if ( NULL != FullDirName ) {
  27.       // append "\." to name to check for directory
  28.       sprintf(TestDir,"%s\\.",FullDirName);
  29.       if ( 0 != DirName[0]
  30.         && '\\' != DirName[strlen(DirName)-1]
  31.         && NULL != Directory(TestDir,FALSE,0xFFFF,FATTR_SUBDIR) ) {
  32.          DirIsValid = TRUE
  33.       }
  34.    }
  35.    if ( !DirIsValid  &&  PrintMessageIfInvalid )
  36.       fprintf(stderr,"\n\"%s\" IS NOT A VALID SUB-DIRECTORY NAME.\a\n",DirName);
  37.    return(DirIsValid);
  38. }
  39.  
  40. Instructions()
  41. {
  42.    printf("\n")
  43.    printf("   ValidDir.cmd - Test if a subdirectory name is valid\n")
  44.    printf("\n")
  45.    printf("   USAGE: ValidDir SubdirSpec [PrintError]\n")
  46.    printf("\n")
  47.    printf("          Check if subdirectory name is valid, and return ERRORLEVEL 0 if it is\n")
  48.    printf("          and ERRORLEVEL 1 if it is not.  If PrintError is supplied then a\n")
  49.    printf("          message will be printed if directory is invalid.\n")
  50.    printf("\n")
  51. }
  52.  
  53.