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

  1. EXTPROC CEnvi2
  2. /*****************************************************************
  3.  *** WPFolder - open a directory as a folder in the workplace, ***
  4.  *** ver.1      and switch to it unless told not to            ***
  5.  *****************************************************************/
  6.  
  7. #include <PMdll.lib>
  8.  
  9. #define  NOSWITCH_CMD   "NOSWITCH"
  10.  
  11. main(argc,argv)
  12. {
  13.    if ( 3 < argc  ||  !strcmp(argv[1],"/?")  ||  !stricmp(argv[1],"/help") )
  14.       Instructions();
  15.    else
  16.       // create for input folder or for current dir if no input folder
  17.       CreateWPFolder( 2 <= argc ? argv[1] : ".",
  18.                       (3 <= argc) ? stricmp(argv[2],NOSWITCH_CMD) : TRUE );
  19. }
  20.  
  21. CreateWPFolder(PathSpec,SwitchRequested)
  22. {
  23.    // use the ValidSubdirectoryName() routine in ValidDir.cmd to check on dir name
  24.    if ( !ValidDirectoryName(PathSpec,TRUE) ) {
  25.       printf("\a\"%s\" is not a valid folder name\n",PathSpec);
  26.    } else {
  27.       // create object using full path name
  28.       FullName = FullPath(PathSpec);
  29.       sprintf(SetupString,"SHADOWID=%s;OPEN=DEFAULT;",FullName);
  30.       // let the WinCreateObject() routin in PMdll.cmm call the dll
  31.       handle = WinCreateObject("WPShadow",FullName,SetupString,
  32.                                "<WP_NOWHERE>",CO_REPLACEIFEXISTS);
  33.       if ( handle == NULL )
  34.          printf("\aError creating workplace folder\n");
  35.       else if ( SwitchRequested ) {
  36.          // call the Switch.cmd command to switch to the selected folder
  37.          FileParts = SplitFileName(FullName);
  38.          system("start /C Switch.cmd %s%s",FileParts.name,FileParts.ext);
  39.       }
  40.    }
  41. }
  42.  
  43. ValidDirectoryName(DirName)
  44.    // test if DirName is a valid directory name.  Return TRUE if it is else FALSE.
  45. {
  46.    DirIsValid = FALSE; // assume failure
  47.    FullDirName = FullPath(DirName);
  48.    if ( NULL != FullDirName ) {
  49.       // check for root dir, which is always valid
  50.       if ( !strcmp(":\\",FullDirName+1) ) {
  51.          DirIsValid = TRUE;
  52.       } else {
  53.          // append "\." to name to check for directory
  54.          sprintf(TestDir,"%s\\.",FullDirName);
  55.          if ( 0 != DirName[0]
  56.            && '\\' != DirName[strlen(DirName)-1]
  57.            && NULL != Directory(TestDir,FALSE,0xFFFF,FATTR_SUBDIR) ) {
  58.             DirIsValid = TRUE
  59.          }
  60.       }
  61.    }
  62.    return(DirIsValid);
  63. }
  64.  
  65. Instructions()
  66. {
  67.    printf("\n")
  68.    printf("WPFolder - Create a Workplace Folder for a directory name\n")
  69.    printf("\n")
  70.    printf("SYNTAX: WPFOLDER [DirSpec [%s]]\n",NOSWITCH_CMD)
  71.    printf("\n")
  72.    printf("Where:  DirSpec  - specification for a file-system directory\n")
  73.    printf("        NOSWITCH - if this is entered then do NOT switch to the folder\n")
  74.    printf("\n")
  75.    printf("Examples: WPFolder       - Create folder for the current directory\n")
  76.    printf("          WPFolder C:\\   - Create folder for root drive of C:\n")
  77.    printf("          WPFolder C:\\OS2\\DLL\n")
  78.    printf("          WPFolder C:\\OS2\\DLL %s\n",NOSWITCH_CMD)
  79.    printf("\n")
  80. }
  81.  
  82.