/* AR-921013 CH UT_DeleteDir Sletter et directory CD ================================================================== CD Formål: CD Sletter et directory. CD CD PARAMETERLISTE: CD Type Navn I/U Merknad CD ------------------------------------------------------------------ CD char *pszPath i Directory-navn CD short sStatus r Status; 0=OK, annen verdi er feil. CD CD Bruk: sStatus = UT_DeleteDir(szPath); ================================================================== */ SK_EntPnt_UT short UT_DeleteDir(char *pszPath) { #ifdef LINUX return (short)rmdir(pszPath); #endif #ifdef UNIX return (short)rmdir(pszPath); #endif #ifdef OS232 return (short)DosDeleteDir(pszPath); #endif #ifdef OS216 return (short)rmdir(pszPath); #endif #ifdef WIN32 return (short)_rmdir(pszPath); #endif #ifdef BORLAND return (short)rmdir(pszPath); #endif }
int __PHYSFS_platformDelete(const char *path) { if (__PHYSFS_platformIsDirectory(path)) return(os2err(DosDeleteDir(path)) == NO_ERROR); return(os2err(DosDelete(path) == NO_ERROR)); } /* __PHYSFS_platformDelete */
PRInt32 _PR_MD_RMDIR(const char *name) { PRInt32 rc; if ( (rc = DosDeleteDir((char *)name)) == NO_ERROR) { return 0; } else { _PR_MD_MAP_RMDIR_ERROR(rc); return -1; } }
_WCRTLINK int __F_NAME(rmdir,_wrmdir)( const CHAR_TYPE *path ) { APIRET rc; #ifdef __WIDECHAR__ size_t rcConvert; char mbcsPath[ MB_CUR_MAX * _MAX_PATH ]; unsigned char *p; /*** Convert the wide character string to a multibyte string ***/ rcConvert = wcstombs( mbcsPath, path, sizeof( mbcsPath ) ); p = _mbsninc( (unsigned char *)mbcsPath, rcConvert ); *p = '\0'; #endif #ifdef _M_I86 rc = DosRmDir( (PSZ)__F_NAME(path,mbcsPath), 0 ); #else rc = DosDeleteDir( (PSZ)__F_NAME(path,mbcsPath) ); #endif if( rc != 0 ) { return( __set_errno_dos( rc ) ); } return( 0 ); /* indicate no error */ }
APIRET DeleteDir (PSZ pszPath) { APIRET rc = NO_ERROR; /* API-Returncode */ int iAnswer; /* answer from the user confirmation prompt */ FILESTATUS fStat; /* filestatus structure for attributes */ Globals.ulDirectoriesScanned++; /* update the statistics */ if (!Options.fsDontDeleteDirs) /* if we have to remove subdirs */ { /* remove the directory */ if (Options.fsSimulation) /* simulate deletion only ? */ printf ("\n rd %s", pszPath); else { if (Options.fsVerbose || /* verbose output ? */ Options.fsConfirmationPrompt) printf ("\nRemoving %s ", pszPath); if (Options.fsConfirmationPrompt) /* prompt for every deletion ? */ { iAnswer = ToolsConfirmationQuery(); /* ask the user */ switch (iAnswer) { case 0: /* no */ return (NO_ERROR); /* abort processing */ case 1: /* yes */ break; /* continue ... */ case 2: /* escape */ exit (1); /* PH: urgs, terminate the process */ } } rc = DosDeleteDir(pszPath); /* OK, remove that thing ! */ if ( (rc == ERROR_ACCESS_DENIED) && /* check for READ-ONLY */ Options.fsRemoveAttributes) { rc = DosQueryPathInfo (pszPath, /* query file information */ FIL_STANDARD, &fStat, sizeof(fStat)); if (rc == NO_ERROR) /* check for errors */ { fStat.attrFile = FILE_NORMAL; /* reset the attributes */ rc = DosSetPathInfo (pszPath, /* set the information */ FIL_STANDARD, &fStat, sizeof(fStat), 0L); if (rc == NO_ERROR) /* check for errors */ /* now try again */ rc = DosDeleteDir(pszPath); /* OK, remove that thing ! */ } } if (rc == NO_ERROR) /* check for errors */ Globals.ulDirectoriesDeleted++; /* update the statistics */ } } return (rc); /* ok */ }
/*@ XFile::DeleteDirectory(const char *path) @group directorys @remarks Delete a directory @parameters char * path of the directory to delete */ ULONG XFile::DeleteDirectory(const char *path) { return DosDeleteDir((PSZ) path); }
void main(int argc,char *argv[]) { char *basedir, *p; FILEFINDBUF3 find; HDIR dirhandle; ULONG srch_cnt; int newdrive, urdrive, rootdir, dotdir, dotdotdir; int asking=TRUE, retcode=TRUE; while (--argc) { ++argv; if ((argv[0][0] == '/') || (argv[0][0] == '-')) { switch(toupper(argv[0][1])) { case 'Y': asking = FALSE; break; #ifdef __OS2__ case 'F': forcedel = 1; break; #endif default : printf("Invalid switch - %c\n", argv[0][1]); abort(); } } else break; } if (!argc) { puts("DELTREE2 v1.0\nRequired parameter missing"); abort(); } urdrive = getdisk(); #ifdef __OS2__ DosError(FERR_DISABLEHARDERR); #endif /* Process each command line parameter */ while (argc--) { basedir = *argv++; if (asking) { printf("Delete directory \"%s\" and all its subdirectories? [yn] ", basedir); if (!getyn()) continue; } setdisk(urdrive); srch_cnt = 1; dirhandle = HDIR_CREATE; findret = DosFindFirst(basedir, &dirhandle, MUST_HAVE_DIRECTORY, &find, sizeof(find), &srch_cnt, FIL_STANDARD); if (findret == 0) { #ifndef __OS2__ dirhandle = 1; #endif DosFindClose(dirhandle); } else continue; /* no such directory, goto next argument */ if (basedir[1] == ':') { /* Need to change drives */ newdrive = toupper(basedir[0])-'A'; if (newdrive != urdrive) { setdisk(newdrive); if (newdrive != getdisk()) continue; /* cannot switch drives, goto next argument */ } basedir+=2; } assert (NULL != (p=getcwd(NULL, MAXPATH))); dotdir = !strcmp(basedir, ".") || !strcmp(basedir, p+2); free(p); dotdotdir = !strcmp(basedir, ".."); rootdir = (!strcmp(basedir,"\\") || !strcmp(basedir,"/")); printf("Deleting %s...\n", basedir); if (rootdir) { CHDIR("\\"); retcode &= nextdir(FALSE); } else if (dotdir) { retcode &= nextdir(FALSE); } else if (dotdotdir) { CHDIR(".."); retcode &= nextdir(FALSE); } else { if (CHDIR(basedir)) continue /* cannot change directory - goto next argument */; retcode &= nextdir(FALSE); CHDIR(".."); #ifndef DBG retcode &= (0 == DosDeleteDir(basedir)); #endif } /* goto next argument */ } setdisk(urdrive); exit(retcode ? 0 : 1); }
int nextdir(int toplev) { #ifdef __OS2__ FILEFINDBUF3 find; ULONG srch_cnt; HDIR dirhandle; APIRET findret; #else struct ffblk find; ULONG srch_cnt; HDIR dirhandle; int findret; #endif int retcode=TRUE, c, rc, nomore; #ifdef DBG printf("entered nextdir %d\n", nextdirdepth++); #endif srch_cnt = 1; dirhandle = HDIR_CREATE; findret = DosFindFirst("*.*", &dirhandle, MUST_HAVE_DIRECTORY, &find, sizeof(find), &srch_cnt, FIL_STANDARD); #ifdef __OS2__ nomore = (findret == ERROR_NO_MORE_FILES); #else nomore = ((findret == -1) && (_doserrno == ENMFILE)); if (!nomore) dirhandle = 1; #endif #ifdef DBG printf("DosFindFirstDir returned %d(%d)\n", (int) findret, nomore); DOSFINDBAD(findret); assert(dirhandle != HDIR_CREATE); #endif if (nomore) findret = 0; while (!nomore) { if ((findret == 0) && (FNAME != '.') && (FATTR & FILE_DIRECTORY)) { /* descend next level */ if (toplev) printf("Deleting %s...\n", &FNAME); #ifdef DBG printf("descending to scan %s\n", &FNAME); assert(0 == CHDIR(&FNAME)); retcode &= nextdir(FALSE); /* ascend level and onto next directory */ assert(0 == CHDIR("..")); printf("removing dir %s\n", &FNAME); #else /* descend level */ if (CHDIR(&FNAME)) { /* descent impossible */ retcode = FALSE; } else { /* process next directory */ retcode &= nextdir(FALSE); /* ascend level */ if (CHDIR("..")) { /* Something woefully wrong ... */ if (dirhandle != HDIR_CREATE) { DosFindClose(dirhandle); dirhandle = HDIR_CREATE; } return(FALSE); } else { /* delete empty directory */ retcode &= (0 == DosDeleteDir(&FNAME)); } } #endif } /* Position to next entry */ findret = DosFindNext(dirhandle, &find, sizeof(find), &srch_cnt); #ifdef __OS2__ nomore = (findret == ERROR_NO_MORE_FILES); #else nomore = ((findret == -1) && (_doserrno == ENMFILE)); #endif #ifdef DBG printf("DosFindNextDir returned %d(%d)\n", (int) findret, nomore); DOSFINDBAD(findret); #endif if (nomore) findret = 0; /* Process next entry */ continue; } if (dirhandle != HDIR_CREATE) { DosFindClose(dirhandle); dirhandle = HDIR_CREATE; } srch_cnt = 1; /* Now delete the files */ findret = DosFindFirst("*.*",&dirhandle, FILE_ABNORMAL, &find, sizeof(find), &srch_cnt, FIL_STANDARD); #ifdef __OS2__ nomore = (findret == ERROR_NO_MORE_FILES); #else nomore = ((findret == -1) && (_doserrno == ENMFILE)); if (!nomore) dirhandle = 1; #endif #ifdef DBG printf("DosFindFirstFile returned %d(%d)\n", (int) findret, nomore); DOSFINDBAD(findret); #endif if (nomore) findret = 0; while (!nomore) { if (findret == 0) { /* Process if file OK */ if (toplev) printf("Deleting %s...\n", &FNAME); #ifdef DBG if (!findret && (FATTR & FILE_ABNORMAL)) printf("making normal and %sdeleting %s\n", dbgdel[forcedel], &FNAME); else printf("%sdeleting %s\n", dbgdel[forcedel], &FNAME); #else if (!findret && (FATTR & FILE_ABNORMAL)) rc = _chmod(&FNAME, 1, 0); if (!rc) { #ifdef __OS2__ if (forcedel) retcode &= (0 == DosForceDelete(&FNAME)); else #endif retcode &= (0 == DosDelete(&FNAME)); } else retcode = FALSE; #endif } /* Advance to next file */ findret = DosFindNext(dirhandle, &find, sizeof(find), &srch_cnt); #ifdef __OS2__ nomore = (findret == ERROR_NO_MORE_FILES); #else nomore = ((findret == -1) && (_doserrno == ENMFILE)); #endif #ifdef DBG printf("DosFindNextFile returned %d(%d)\n", (int) findret, nomore); DOSFINDBAD(findret); #endif if (nomore) findret = 0; /* Process next file */ continue; } if (dirhandle != HDIR_CREATE) DosFindClose(dirhandle); #ifdef DBG printf("leaving nextdir %d\n", --nextdirdepth); #endif return(retcode); }
unsigned LocalRmDir( char *name ) /***************************/ { return( StashErrCode( DosDeleteDir( name ), OP_LOCAL ) ); }
bool LocalInteractive( sys_handle fh ) /************************************/ { APIRET type; APIRET flags; //NYI: really should convert fh to sys_handle, but I know that it's // a one-to-one mapping #ifdef _M_I86 if( DosQHandType( fh, &type, &flags ) ) { #else if( DosQueryHType( fh, &type, &flags ) ) { #endif return( false ); } if( type == 1 ) { /* device type */ return( true ); } return( false ); } void LocalGetBuff( char *buff, unsigned size ) /********************************************/ { struct _STRINGINBUF length; if( size > UCHAR_MAX ) { size = UCHAR_MAX; } length.cb = size; length.cchIn = 0; if( KbdStringIn( buff, &length, 0, 0 ) ) { buff[0] = '\r'; buff[1] = NULLCHAR; return; } buff[length.cchIn] = NULLCHAR; } error_handle LocalRename( const char *from, const char *to ) /**********************************************************/ { #ifdef _M_I86 return( StashErrCode( DosMove( from, to, 0 ), OP_LOCAL ) ); #else return( StashErrCode( DosMove( from, to ), OP_LOCAL ) ); #endif } error_handle LocalMkDir( const char *name ) /*****************************************/ { #ifdef _M_I86 return( StashErrCode( DosMkDir( name, 0 ), OP_LOCAL ) ); #else return( StashErrCode( DosCreateDir( name, NULL ), OP_LOCAL ) ); #endif } error_handle LocalRmDir( const char *name ) /*****************************************/ { #ifdef _M_I86 return( StashErrCode( DosRmDir( name, 0 ), OP_LOCAL ) ); #else return( StashErrCode( DosDeleteDir( name ), OP_LOCAL ) ); #endif } error_handle LocalSetDrv( int drv ) /*********************************/ { #ifdef _M_I86 return( StashErrCode( DosSelectDisk( drv + 1 ), OP_LOCAL ) ); #else return( StashErrCode( DosSetDefaultDisk( drv + 1 ), OP_LOCAL ) ); #endif } int LocalGetDrv( void ) /*********************/ { APIRET drive; ULONG map; #ifdef _M_I86 if( DosQCurDisk( &drive, &map ) ) { #else if( DosQueryCurrentDisk( &drive, &map ) ) { #endif return( -1 ); } return( drive - 1 ); } error_handle LocalSetCWD( const char *name ) /******************************************/ { #ifdef _M_I86 return( StashErrCode( DosChDir( name, 0 ), OP_LOCAL ) ); #else return( StashErrCode( DosSetCurrentDir( name ), OP_LOCAL ) ); #endif } long LocalGetFileAttr( const char *name ) /***************************************/ { #ifdef _M_I86 USHORT attr; if( DosQFileMode( name, &attr, 0 ) ) { return( -1L ); } return( attr ); #else FILESTATUS3 fileinfo; if( DosQueryPathInfo( name, FIL_STANDARD, &fileinfo, sizeof( fileinfo ) ) ) { return( -1L ); } return( fileinfo.attrFile ); #endif }
//------------------------------ CMD_DosDeleteDir ------------------------------ void CMD_DosDeleteDir(HFILE hFile,LXIOCPA_DMN_CMDPARMPACKET* pParam ,PLXONENAMESTRUCT on) { pParam->rc=DosDeleteDir(on->name); }
int Q_rmdir (const char *path) { APIRET rc = DosDeleteDir(path); return (rc == NO_ERROR)? 0 : -1; }