home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cenvi23.zip / RMDIR.CMM < prev    next >
Text File  |  1996-02-12  |  3KB  |  103 lines

  1. /*
  2.  * rmdir.cmm
  3.  *
  4.  * This .CMM file implements a DOS-like RD command.
  5.  */
  6.  
  7. #include "netware.lib"
  8. #include "filename.lib"
  9.  
  10. usage()
  11. {
  12.   printf("Use the RD command to remove an empty directory.\n");
  13.   printf("Syntax:\n");
  14.   printf("  RD [drive:][path]\n");
  15.   printf("where:\n");
  16.   printf("  drive:/path  Specifies the directory to remove. It must be empty.\n");
  17.   exit(EXIT_FAILURE);
  18. }
  19.  
  20. /* ---------------------------------------------------------------------- */
  21.  
  22. DeleteDirectory(pDirSpec)
  23. {
  24.    lReg.ah = 0x3A;
  25.    if !defined(_DOS32_)
  26.       lReg.ds = segment(pDirSpec), lReg.dx = offset(pDirSpec);
  27.    else
  28.       lReg.dx = pointer(pDirSpec);
  29.    return interrupt(0x21,lReg);
  30. }
  31.  
  32. myrmdir(dir)
  33. {
  34.   if( defined(_NWNLM_) ) return rmdir(dir);
  35.   if( defined(_OS2_) )
  36.     {
  37. #define ORD_DOS32DELETEDIR 226
  38.       return DynamicLink("DOSCALLS",ORD_DOS32DELETEDIR,BIT32,CDECL,dir);
  39.     }
  40.   if( defined(_NTCON_) || defined(_NTWIN_) || defined(_95CON_) ||
  41.       defined(_95WIN_) )
  42.     {
  43.       return !DynamicLink("KERNEL32","RemoveDirectoryA",STDCALL,dir);
  44.     }
  45.   if( defined(_DOS_) || defined(_WINDOWS_) || defined(_DOS32_) )
  46.     {
  47.       return !DeleteDirectory(dir);
  48.     }
  49.  
  50.   printf("Rmdir.cmm does not support this version of CEnvi.\n");
  51.   return 1;
  52. }
  53.  
  54. /* ---------------------------------------------------------------------- */
  55.  
  56. main(argc,argv)
  57. {
  58.   if( argc!=2 ) usage();
  59.   if( !strcmp(argv[1],"/?") ) usage();
  60.  
  61.   source = argv[1];
  62.   s = strlen(source);
  63.   if( source[s-1]==filename_separator[0] ) source[s-1] = '\0';
  64.  
  65.   dest = Directory(source);
  66.   if( dest==NULL )
  67.     {
  68.       if( isalpha(source[0]) && source[1]==':' &&
  69.           (source[2]=='\0' || source[2]=='/' || source[2]=='\\') )
  70.         {
  71.           printf("You may not remove volume \"%s\".\n",source);
  72.         } else {
  73.           printf("There is no directory named \"%s\".\n",source);
  74.         }
  75.       exit(EXIT_FAILURE);
  76.     } else {
  77.       if( GetArraySpan(dest)!=0 )
  78.     {
  79.       printf("You may not specify more than one directory.\n");
  80.       exit(EXIT_FAILURE);
  81.     }
  82.       if( (dest[0].attrib & _A_SUBDIR)==0 )
  83.     {
  84.       printf("\"%s\" is not a directory.\n",source);
  85.       exit(EXIT_FAILURE);
  86.     }
  87.     }
  88.  
  89.   strcpy(tmp,source);
  90.   if( tmp[strlen(tmp)-1]!='/' ) strcat(tmp,"/");
  91.   strcat(tmp,"*.*");
  92.   if( Directory(tmp) )
  93.     {
  94.       printf("\"%s\" cannot be removed; directory not empty.\n",source);
  95.       exit(EXIT_FAILURE);
  96.     }
  97.   if( myrmdir(source) )
  98.     {
  99.       printf("\"%s\" was not removed.\n",source);
  100.     }
  101.   exit(EXIT_SUCCESS);
  102. }
  103.