int teardown_test(void) { char dirname[_MAX_PATH]; size_t len; int i; printf ("Begin cleanup...\n"); if (_getcwd(dirname, sizeof(dirname)/sizeof(char)) != NULL && (len = strlen(dirname)) > sizeof(TESTDIR)/sizeof(char) && !strcmp(dirname + len + 1 - sizeof(TESTDIR)/sizeof(char), TESTDIR)) { /* fallthrough */ } else { /* did we create the directory? */ if (!_rmdir( TESTDIR )) { fprintf(stderr, "Removed test directory\n"); return 0; } else { if (errno == ENOTEMPTY) { if (_chdir(TESTDIR)) { fprintf(stderr, "Can't change to test directory. Aborting cleanup.\n"); return -1; } else { /* fallthrough */ } } else { return -1; } } } fprintf(stderr, "Cleaning up test directory %s ...\n", TESTDIR); for (i=0; i < n_dir_entries; i++) { if (_unlink(dir_entries[i])) { /* if the test setup failed, we expect this to happen for at least some files */ } } if (_chdir("..")) { fprintf(stderr, "Can't escape test directory. Giving in.\n"); return -1; } if (_rmdir( TESTDIR )) { fprintf(stderr, "Can't remove test directory.\n"); return -1; } printf("Cleaned up test directory\n"); return 0; }
static int runSupFileServiceTests (void) { printf ("==== SUP:FileService\n"); struct stat dirStat; BRFileService fs; char *path; char *currency = "btc", *network = "mainnet"; char *type1 = "foo"; // // Try to create a directory that is not writable; expect fileServiceCreate() to fail. // path = "private"; if (0 == stat (path, &dirStat)) _rmdir (path); if (0 != mkdir (path, 0000)) return 0; fs = fileServiceCreate(path, currency, network, NULL, NULL); if (NULL != fs) return fileServiceTestDone(path, 0); // // Create a directory that is writeable; expect fileServiceCreate to succeed. // if (0 == stat (path, &dirStat)) _rmdir (path); if (0 != mkdir (path, 0700)) return 0; fs = fileServiceCreate(path, currency, network, NULL, NULL); if (NULL == fs) return fileServiceTestDone(path, 0); // Confirm the full path exists. char fullpath[1024]; sprintf (fullpath, "%s/%s/%s", path, currency, network); if (0 != stat (fullpath, &dirStat)) return fileServiceTestDone (path, 0); // change the fullpath permissions; expect 'defineType' to fail. chmod (fullpath, 0000); if (1 == fileServiceDefineType(fs, type1, 0, NULL, NULL, NULL, NULL)) return fileServiceTestDone (path, 0); // and can't set the current version on a bad type if (1 == fileServiceDefineCurrentVersion(fs, type1, 0)) return fileServiceTestDone (path, 0); // change the permission to allow writing chmod (fullpath, 0700); if (1 != fileServiceDefineType(fs, type1, 0, NULL, NULL, NULL, NULL)) return fileServiceTestDone (path, 0); if (1 != fileServiceDefineCurrentVersion(fs, type1, 0)) return fileServiceTestDone (path, 0); // Good, finally. return fileServiceTestDone(path, 1); }
// Given a directory remove the files located within it and then the directory itself void removeDirectory(std::string directory) { std::string CWD = getCurrentDirectory(); directory = CWD + DIR_SEPARATOR + directory; WIN32_FIND_DATA data; HANDLE h = FindFirstFile((directory + DIR_SEPARATOR + "*").c_str(), &data); if (h != NULL) { SetFileAttributes(directory.c_str(), FILE_ATTRIBUTE_NORMAL); FindNextFile(h, &data); // .. FindNextFile(h, &data); // . do { std::string filename = directory + DIR_SEPARATOR + data.cFileName; if (!SetFileAttributes(filename.c_str(), FILE_ATTRIBUTE_NORMAL)) { logEvent(ERROR,filename + ": " + ConvertLastErrorToString()); } int result = _unlink(filename.c_str()); if (result != 0) { logEvent(ERROR, filename + ": " + ConvertLastErrorToString()); } } while (FindNextFile(h,&data)); FindClose(h); } _rmdir(directory.c_str()); }
FRESULT f_unlink ( const XCHAR *path /* Pointer to the file or directory path */ ) { FRESULT ret = FR_OK; const char* target= createFullPath(path); if (-1 == stat(target, &stats)) { return cvtERRNO(); } if (stats.st_mode & S_IFDIR) { if (_rmdir(target) == -1) { ret = FR_DENIED; } } else { // a concatenation of the mmc dir & the requested path if (_unlink(target) == -1) { ret = cvtERRNO(); } } return ret; }
static int fileServiceTestDone (char *path, int success) { struct stat dirStat; if (0 == stat (path, &dirStat)) _rmdir (path); return success; }
void MusicUtils::EmptyDir(CString Dir) { CFileFind finder; CFile cfile; CString Add=L"\\*"; CString DirSpec=Dir+Add; //???????????? BOOL bWorking = finder.FindFile(DirSpec); while (bWorking) { bWorking = finder.FindNextFile(); if(!finder.IsDots()) //???????? { if(finder.IsDirectory()) //???????? { CString strDirectory = finder.GetFilePath(); if(_rmdir((const char*)(LPSTR)(LPCTSTR)strDirectory)==-1) { EmptyDir(strDirectory); } bWorking = finder.FindFile(DirSpec); } else //??????? { cfile.Remove(finder.GetFilePath()); } } } finder.Close(); }
unsigned int CRhoFile::deleteEmptyFolder( const char* szFilePath ){ #if defined(WINDOWS_PLATFORM) return (unsigned int)_rmdir(szFilePath); #else return (unsigned int)rmdir(szFilePath); #endif }
/** Removes a file or an empty directory * @param[in] _zFileName Concerned file / directory * @return orxSTATUS_SUCCESS / orxSTATUS_FAILURE */ orxSTATUS orxFASTCALL orxFile_Remove(const orxSTRING _zFileName) { orxSTATUS eResult = orxSTATUS_FAILURE; /* Checks */ orxASSERT((sstFile.u32Flags & orxFILE_KU32_STATIC_FLAG_READY) == orxFILE_KU32_STATIC_FLAG_READY); orxASSERT(_zFileName != orxNULL); /* Tries to remove it as a file */ if(remove(_zFileName) == 0) { /* Updates result */ eResult = orxSTATUS_SUCCESS; } else { /* Tries to remove it as a directory */ #ifdef __orxWINDOWS__ if(_rmdir(_zFileName) == 0) #else /* __orxWINDOWS__ */ if(rmdir(_zFileName) == 0) #endif /* __orxWINDOWS__ */ { /* Updates result */ eResult = orxSTATUS_SUCCESS; } } /* Done! */ return eResult; }
void DelDB(char* pDb) { char loc[256]; char locfile[256]; CFileFind finder; strcpy(locfile,pDb); //<---所要删除的目录的路径 strcpy(loc,pDb); //<---所要删除的目录的路径 strcat(locfile , "\\*.*"); //<---该目录下所有的文件 int bWorking = finder.FindFile(locfile); while(bWorking) { bWorking = finder.FindNextFile(); if (finder.IsDots()) continue; if (!finder.IsDirectory()) { CString str = finder.GetFilePath(); CFile::Remove( str ); } } finder.Close(); //删除空目录---> if( _rmdir( loc ) == 0 ) std::cout<<"Directory "<<loc<<" was successfully removed\n"; else std::cout<<"Can not remove database"<<loc<<"\n"; ResetDBinfo(); //<---删除数据库之后将全局路径重新设置 }
/////////////////////////////////////////////////////////////////////// // Function : osDeleteDir // Description : Remove a directory // Return Value : - // Comments : void osDeleteDir(const char *n) { #ifdef _WINDOWS _rmdir(n); #else rmdir(n); #endif }
void deleteDirectory( const char* szDirectory ) { std::vector<std::string> aFileNames; getAllFilesInDirectory( szDirectory, aFileNames ); char szFullPath[512]; std::vector<std::string>::iterator iter = aFileNames.begin(); for( ; iter != aFileNames.end(); ++iter ) { const char* szFileName = (*iter).c_str(); if( *iter != "." && *iter != ".." ) { snprintf( szFullPath, sizeof( szFullPath ), "%s/%s/%s", getWriteDirectory(), szDirectory, szFileName ); remove( szFullPath ); } } // for iter = files names begin to end snprintf( szFullPath, sizeof( szFullPath ), "%s/%s", getWriteDirectory(), szDirectory ); #if defined( WIN32 ) _rmdir( szFullPath ); #else rmdir( szFullPath ); #endif // WIN32 }
void removeAllFiles(const string source){ _finddata_t *fileinfo = new _finddata_t; string mask = parser(source); int done, checker; done = _findfirst(mask.c_str(), fileinfo); if (done == -1){ throw exception("cant open remove directory!\n"); } while ((strcmp(fileinfo->name, ".") == 0) || (strcmp(fileinfo->name, "..") == 0)){ checker = _findnext(done, fileinfo); } string src, filename; while (checker != -1){ while (checker != -1 && fileinfo->attrib &_A_SUBDIR){ src = source + fileinfo->name + "\\"; removeAllFiles(src); if (_rmdir(src.c_str()) == -1){ throw exception("cant remove directory!\n"); } checker = _findnext(done, fileinfo); } if (checker != -1){ filename = source + fileinfo->name; if (remove(filename.c_str()) != 0){ throw exception("cant remove file!\n"); } checker = _findnext(done, fileinfo); } } delete fileinfo; _findclose(done); }
int os_rmdir(const char * name){ #if ( defined _WIN32 || defined WIN32 ) return _rmdir(name); #else return rmdir(name); #endif };
/* 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 main(int argc, char *argv[]) { int c; static struct option const long_options[] = { {"help", 0, NULL, 'h'}, {NULL, 0, NULL, 0} }; exit_status = 0; program_name = argv[0]; while((c = getopt_long(argc, argv, "hH", long_options, NULL)) != -1) { switch(c) { case 'h': case 'H': rmdir_usage_exit(EXIT_SUCESS); break; default: rmdir_usage_exit(EXIT_FAILURE); break; } } if(optind == argc) rmdir_usage_exit(EXIT_FAILURE); while(optind < argc) exit_status = _rmdir(argv[optind++]); exit(exit_status); }
static void clean_temp_dirs () { bool err= false; array<string> a= read_directory (main_tmp_dir, err); #ifndef __MINGW32__ for (int i=0; i<N(a); i++) if (is_int (a[i])) if (!process_running (as_int (a[i]))) if (a[i] != as_string ((int) getpid ())) system ("rm -rf", url (main_tmp_dir) * url (a[i])); #else /* delete the directories after 7 days */ time_t ts = as_int (basename (url_temp_dir_sub ())) - (3600 * 24 * 7 ); for (int i=0; i<N(a); i++) if (is_int (a[i])) { time_t td= as_int (a[i]); if (td < ts) { url cur = url (main_tmp_dir) * url (a[i]); array<string> f= read_directory (cur, err); for (int j=0; j<N(f); j++) remove (cur * url (f[j])); _rmdir (as_charp (as_string (cur))); } } #endif }
void ToolBox::rmdir(const char *pathname) { #if defined(_WIN32) || defined(__MINGW32__) _rmdir(pathname); #else ::rmdir(pathname); #endif }
bool Path::destroyDirectory() const { #if WENDY_SYSTEM_WIN32 return _rmdir(path.c_str()) == 0; #else return rmdir(path.c_str()) == 0; #endif }
//////////////////////////////////////////////////////////////////////// // 描 述: 删除一个指定的目录,只有当目录为空才能删除成功 // 作 者: 邵凯田 // 创建时间: 2011-11-18 11:42 // 参数说明: @dir待删除的目录 // 返 回 值: true删除目录成功,false失败 ////////////////////////////////////////////////////////////////////////// bool SDir::removeDir(SString dir) { #ifdef WIN32 return _rmdir(dir.data()) == 0; #else return rmdir(dir.data()) == 0; #endif }
void Delete_Preloaded_MP3s(void) { int i; for(i = 0; i < 100; i++) Delete_Preloaded_MP3(i); _rmdir(PRELOADED_MP3_DIRECTORY); // this will only delete the directory if it's empty, which is good. but it won't delete the directory if Windows Explorer has acquired and leaked the directory handle as it loves to do, which is bad. oh well. }
bool Platform::dirRemove(const std::string& path) { if (_rmdir(path.c_str()) != 0) { std::string error_msg = "Platform::dirRemove (" + path + ")"; perror(error_msg.c_str()); return false; } return true; }
bool Path::destroyDirectory() const { #if NORI_SYSTEM_WIN32 return _rmdir(m_string.c_str()) == 0; #else return rmdir(m_string.c_str()) == 0; #endif }
int rob_rmdir (const char* path) { #ifdef WIN32 return _rmdir(path); // http://msdn.microsoft.com/en-us/library/2fkk4dzw.aspx, currently (15.01.2010) only needed for iris install using home path #else return rmdir(path); #endif return -2; }
bool DeleteDisplayData() { char filePath[MAX_PATH]; sprintf_s(filePath, "%s/DBM_MuseumData.json", GetUserDirectory().c_str()); DeleteFile(filePath); _rmdir(GetUserDirectory().c_str()); return false; }
/* * NAME: P_rmdir() * DESCRIPTION: remove an empty directory */ int P_rmdir(const char *path) { char buf[STRINGSZ]; if (path_file(buf, path) == (char *) NULL) { return -1; } return _rmdir(buf); }
bool UDirectory::removeDir(const std::string & dirPath) { int status; #if WIN32 status = _rmdir(dirPath.c_str()); #else status = rmdir(dirPath.c_str()); #endif return status==0; }
static int lua_rmdir(lua_State *L) { const char *s = luaL_checkstring(L, 1); #ifdef _WIN32 int status = _rmdir(s); #else int status = rmdir(s); #endif return pushresult(L, status == 0, s); }
void deleteDirectory(const char *path) { #if __S3E__ s3eFileDeleteDirectory(path); #else #ifdef WIN32 _rmdir(path); #else rmdir(path); #endif #endif }
void CNFS2Prog::ProcedureRMDIR(void) { char *path; PrintLog("RMDIR"); path = GetFullPath(); if (!CheckFile(path)) return; _rmdir(path); m_pOutStream->Write(NFS_OK); }
static int UpgradeNSIS(void) { std::string installPath = GetNSISInstallPath(); if (installPath.empty()) return 0; std::string uninstallerPath = installPath + "\\uninstall.exe"; if (!PathExists(uninstallerPath)) return 0; std::string dataPath = GetIcingaDataPath(); if (dataPath.empty()) return 1; bool moveUserData = !PathExists(dataPath); /* perform open heart surgery on the user's data dirs - yay */ if (moveUserData) { MkDir(dataPath.c_str()); std::string oldNameEtc = installPath + "\\etc"; std::string newNameEtc = dataPath + "\\etc"; if (!CopyDirectory(oldNameEtc, newNameEtc)) return 1; std::string oldNameVar = installPath + "\\var"; std::string newNameVar = dataPath + "\\var"; if (!CopyDirectory(oldNameVar, newNameVar)) return 1; } ExecuteCommand(uninstallerPath, "/S _?=" + installPath); _unlink(uninstallerPath.c_str()); if (moveUserData) { std::string oldNameEtc = installPath + "\\etc"; if (!DeleteDirectory(oldNameEtc)) return 1; std::string oldNameVar = installPath + "\\var"; if (!DeleteDirectory(oldNameVar)) return 1; _rmdir(installPath.c_str()); } return 0; }