static void test_RemoveDirectoryA(void) { char tmpdir[MAX_PATH]; BOOL ret; GetTempPathA(MAX_PATH, tmpdir); lstrcatA(tmpdir, "Please Remove Me"); ret = CreateDirectoryA(tmpdir, NULL); ok(ret == TRUE, "CreateDirectoryA should always succeed\n"); ret = RemoveDirectoryA(tmpdir); ok(ret == TRUE, "RemoveDirectoryA should always succeed\n"); lstrcatA(tmpdir, "?"); ret = RemoveDirectoryA(tmpdir); ok(ret == FALSE && (GetLastError() == ERROR_INVALID_NAME || GetLastError() == ERROR_PATH_NOT_FOUND), "RemoveDirectoryA with ? wildcard name should fail, ret=%s error=%d\n", ret ? " True" : "False", GetLastError()); tmpdir[lstrlenA(tmpdir) - 1] = '*'; ret = RemoveDirectoryA(tmpdir); ok(ret == FALSE && (GetLastError() == ERROR_INVALID_NAME || GetLastError() == ERROR_PATH_NOT_FOUND), "RemoveDirectoryA with * wildcard name should fail, ret=%s error=%d\n", ret ? " True" : "False", GetLastError()); }
bool FileSystem::FolderRemove(const String& path, bool recursive /*= true*/) const { if (!IsFolderExist(path)) return false; if (!recursive) return RemoveDirectoryA(path.Data()) == TRUE; WIN32_FIND_DATA f; HANDLE h = FindFirstFile((path + "/*").Data(), &f); if (h != INVALID_HANDLE_VALUE) { do { if (strcmp(f.cFileName, ".") == 0 || strcmp(f.cFileName, "..") == 0) continue; if (f.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY) FolderRemove(path + "/" + f.cFileName, true); else FileDelete(path + "/" + f.cFileName); } while (FindNextFile(h, &f)); } FindClose(h); return RemoveDirectoryA(path.Data()) == TRUE; }
BOOL DeleteDirectory(const char* sPath) { HANDLE hFind; // file handle WIN32_FIND_DATAA FindFileData; char DirPath[MAX_PATH]; char FileName[MAX_PATH]; strcpy(DirPath,sPath); strcat(DirPath,"\\*"); // searching all files strcpy(FileName,sPath); strcat(FileName,"\\"); hFind = FindFirstFileA(DirPath,&FindFileData); // find the first file if(hFind == INVALID_HANDLE_VALUE) return FALSE; strcpy(DirPath,FileName); bool bSearch = true; while(bSearch) { // until we finds an entry if(FindNextFileA(hFind,&FindFileData)) { if(IsDots(FindFileData.cFileName)) continue; strcat(FileName,FindFileData.cFileName); if((FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { // we have found a directory, recurse if(!DeleteDirectory(FileName)) { FindClose(hFind); return FALSE; // directory couldn't be deleted } RemoveDirectoryA(FileName); // remove the empty directory strcpy(FileName,DirPath); } else { if(!DeleteFileA(FileName)) { // delete the file FindClose(hFind); return FALSE; } strcpy(FileName,DirPath); } } else { if(GetLastError() == ERROR_NO_MORE_FILES) // no more files there bSearch = false; else { // some error occured, close the handle and return FALSE FindClose(hFind); return FALSE; } } } FindClose(hFind); // closing file handle return RemoveDirectoryA(sPath); // remove the empty directory }
static void test_inffilelistA(void) { static const char inffile2[] = "test2.inf"; static const char *inf = "[Version]\n" "Signature=\"$Chicago$\""; char buffer[MAX_PATH] = { 0 }; char dir[MAX_PATH], *p; DWORD expected, outsize; BOOL ret; if(!pSetupGetInfFileListA) { win_skip("SetupGetInfFileListA not present\n"); return; } /* create a private directory, the temp directory may contain some * inf files left over from old installations */ if (!GetTempFileNameA(CURR_DIR, "inftest", 1, dir)) { win_skip("GetTempFileNameA failed with error %d\n", GetLastError()); return; } if (!CreateDirectoryA(dir, NULL )) { win_skip("CreateDirectoryA(%s) failed with error %d\n", dir, GetLastError()); return; } if (!SetCurrentDirectoryA(dir)) { win_skip("SetCurrentDirectoryA failed with error %d\n", GetLastError()); RemoveDirectoryA(dir); return; } create_inf_file(inffile, inf); create_inf_file(inffile2, inf); /* mixed style */ expected = 3 + strlen(inffile) + strlen(inffile2); ret = pSetupGetInfFileListA(dir, INF_STYLE_OLDNT | INF_STYLE_WIN4, buffer, MAX_PATH, &outsize); ok(ret, "expected SetupGetInfFileListA to succeed!\n"); ok(expected == outsize, "expected required buffersize to be %d, got %d\n", expected, outsize); for(p = buffer; lstrlenA(p) && (outsize > (p - buffer)); p+=lstrlenA(p) + 1) ok(!lstrcmpA(p,inffile2) || !lstrcmpA(p,inffile), "unexpected filename %s\n",p); DeleteFileA(inffile); DeleteFileA(inffile2); SetCurrentDirectoryA(CURR_DIR); RemoveDirectoryA(dir); }
static void test_fullpath(void) { char full[MAX_PATH]; char tmppath[MAX_PATH]; char prevpath[MAX_PATH]; char level1[MAX_PATH]; char level2[MAX_PATH]; char teststring[MAX_PATH]; char *freeme; BOOL rc,free1,free2; free1=free2=TRUE; GetCurrentDirectoryA(MAX_PATH, prevpath); GetTempPathA(MAX_PATH,tmppath); strcpy(level1,tmppath); strcat(level1,"msvcrt-test\\"); rc = CreateDirectoryA(level1,NULL); if (!rc && GetLastError()==ERROR_ALREADY_EXISTS) free1=FALSE; strcpy(level2,level1); strcat(level2,"nextlevel\\"); rc = CreateDirectoryA(level2,NULL); if (!rc && GetLastError()==ERROR_ALREADY_EXISTS) free2=FALSE; SetCurrentDirectoryA(level2); ok(_fullpath(full,"test", MAX_PATH)!=NULL,"_fullpath failed\n"); strcpy(teststring,level2); strcat(teststring,"test"); ok(strcmp(full,teststring)==0,"Invalid Path returned %s\n",full); ok(_fullpath(full,"\\test", MAX_PATH)!=NULL,"_fullpath failed\n"); memcpy(teststring,level2,3); teststring[3]=0; strcat(teststring,"test"); ok(strcmp(full,teststring)==0,"Invalid Path returned %s\n",full); ok(_fullpath(full,"..\\test", MAX_PATH)!=NULL,"_fullpath failed\n"); strcpy(teststring,level1); strcat(teststring,"test"); ok(strcmp(full,teststring)==0,"Invalid Path returned %s\n",full); ok(_fullpath(full,"..\\test", 10)==NULL,"_fullpath failed to generate error\n"); freeme = _fullpath(NULL,"test", 0); ok(freeme!=NULL,"No path returned\n"); strcpy(teststring,level2); strcat(teststring,"test"); ok(strcmp(freeme,teststring)==0,"Invalid Path returned %s\n",freeme); free(freeme); SetCurrentDirectoryA(prevpath); if (free2) RemoveDirectoryA(level2); if (free1) RemoveDirectoryA(level1); }
static void delete_test_files(void) { DeleteFileA("a.txt"); DeleteFileA("b.txt"); DeleteFileA("testdir\\c.txt"); DeleteFileA("testdir\\d.txt"); RemoveDirectoryA("testdir"); RemoveDirectoryA("dest"); DeleteFileA("extract.cab"); }
static void delete_test_files(void) { DeleteFileA("msitest.msi"); DeleteFileA("msitest.cab"); DeleteFileA("msitest\\second\\three.txt"); DeleteFileA("msitest\\first\\two.txt"); DeleteFileA("msitest\\one.txt"); RemoveDirectoryA("msitest\\second"); RemoveDirectoryA("msitest\\first"); RemoveDirectoryA("msitest"); }
bool FileSystemDefault::DeleteDirectory(const char* path) { // The following is copied from the EAIO package. // This code is not smart enough to do a recursive delete, but the one in EAIO is. // We need to implement a recursive delete. // Windows doesn't like it when the directory path ends with a // separator (e.g. '\') character, so we correct for this if needed. if(path && *path) { const size_t nStrlen = strlen(path); if((path[nStrlen - 1] != '/') && (path[nStrlen - 1] != '\\')) { #if defined(EA_PLATFORM_MICROSOFT) return (RemoveDirectoryA(path) != 0); #elif defined(EA_PLATFORM_UNIX) || defined(CS_UNDEFINED_STRING) return (rmdir(path) == 0); #endif } // Else we need to remove the separator. char pathMod[EA::WebKit::FileSystem::kMaxPathLength]; EAW_ASSERT_MSG(nStrlen < EA::WebKit::FileSystem::kMaxPathLength, "Directory path exceeds max path length"); memcpy(pathMod, path, nStrlen - 1); // Force 0 terminator in place of directory separator pathMod[nStrlen - 1] = 0; return DeleteDirectory(pathMod); // Call ourselves recursively. } return false; }
P_LIB_API pboolean p_dir_remove (const pchar *path, PError **error) { if (P_UNLIKELY (path == NULL)) { p_error_set_error_p (error, (pint) P_ERROR_IO_INVALID_ARGUMENT, 0, "Invalid input argument"); return FALSE; } if (!p_dir_is_exists (path)) { p_error_set_error_p (error, (pint) P_ERROR_IO_NOT_EXISTS, 0, "Specified directory doesn't exist"); return FALSE; } if (P_UNLIKELY (RemoveDirectoryA (path) == 0)) { p_error_set_error_p (error, (pint) p_error_get_last_io (), p_error_get_last_system (), "Failed to call RemoveDirectoryA() to remove directory"); return FALSE; } else return TRUE; }
BOOL CleanUpDirs() { DWORD dwAtt; int i; BOOL result = TRUE; for (i = 0; i < numDirTests - 1; i++ ) { dwAtt = GetFileAttributesA(gfaTestsDir[i].name); if( dwAtt != INVALID_FILE_ATTRIBUTES ) { if(!SetFileAttributesA (gfaTestsDir[i].name, FILE_ATTRIBUTE_DIRECTORY)) { result = FALSE; Trace("ERROR:%d: Error setting attributes [%s][%d]\n", GetLastError(), gfaTestsDir[i].name, (FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY)); } if(!RemoveDirectoryA (gfaTestsDir[i].name)) { result = FALSE; Trace("ERROR:%d: Error deleting file [%s][%d]\n", GetLastError(), gfaTestsDir[i].name, dwAtt); } } } return result; }
BOOL CleanUp() { DWORD dwAtt; BOOL result = TRUE; dwAtt = GetFileAttributesA(szFindName); if( dwAtt != INVALID_FILE_ATTRIBUTES ) { if(!SetFileAttributesA (szFindName, FILE_ATTRIBUTE_NORMAL)) { result = FALSE; Trace("ERROR:%d: Error setting attributes [%s][%d]\n", szFindName, FILE_ATTRIBUTE_NORMAL); } if(!DeleteFileA (szFindName)) { result = FALSE; Trace("ERROR:%d: Error deleting file [%s][%d]\n", GetLastError(), szFindName, dwAtt); } } dwAtt = GetFileAttributesA(szDirName); if( dwAtt != INVALID_FILE_ATTRIBUTES ) { if(!RemoveDirectoryA (szDirName)) { result = FALSE; Trace("ERROR:%d: Error deleting file [%s][%d]\n", GetLastError(), szDirName, dwAtt); } } return result; }
/********************************************************************* * _rmdir (MSVCRT.@) * * Delete a directory. * * PARAMS * dir [I] Name of directory to delete. * * RETURNS * Success: 0. The directory indicated by newdir is deleted. * Failure: -1. errno indicates the error. * * NOTES * See RemoveDirectoryA. */ int CDECL MSVCRT__rmdir(const char * dir) { if (RemoveDirectoryA(dir)) return 0; msvcrt_set_errno(GetLastError()); return -1; }
__private_extern__ Boolean _CFRemoveDirectory(const char *path) { #if defined(__WIN32__) return RemoveDirectoryA(path); #else return ((rmdir(path) == 0) ? true : false); #endif }
/* * Arguments: path (string) * Returns: [boolean] */ static int sys_rmdir (lua_State *L) { const char *path = luaL_checkstring(L, 1); int res; #ifndef _WIN32 sys_vm_leave(L); res = rmdir(path); sys_vm_enter(L); #else { void *os_path = utf8_to_filename(path); if (!os_path) return sys_seterror(L, ERROR_NOT_ENOUGH_MEMORY); sys_vm_leave(L); res = is_WinNT ? !RemoveDirectoryW(os_path) : !RemoveDirectoryA(os_path); free(os_path); sys_vm_enter(L); } #endif if (!res) { lua_pushboolean(L, 1); return 1; } return sys_seterror(L, 0); }
bool RemoveDirectory(const char* path) { #ifdef TARGET_WINDOWS return RemoveDirectoryA(path) != 0; #else return rmdir(path) == 0; #endif // TARGET_WINDOWS }
//删除空文件夹 bool zs_ut_s::DeleteDir(std::string path) { #ifdef WIN32 return RemoveDirectoryA(path.c_str()) ? true : false; #else return (rmdir(path.c_str()) == 0) ? true : false; #endif }
bool cFile::DeleteFolder(const AString & a_FolderName) { #ifdef _WIN32 return (RemoveDirectoryA(a_FolderName.c_str()) != 0); #else // _WIN32 return (rmdir(a_FolderName.c_str()) == 0); #endif // else _WIN32 }
/* returns boolean */ int g_remove_dir(const char *dirname) { #if defined(_WIN32) return RemoveDirectoryA(dirname); // test this #else return rmdir(dirname) == 0; #endif }
void releaseFile(const std::string &filename){ std::string lockDir = getFileLock(filename); #if (OCCA_OS == LINUX_OS) || (OCCA_OS == OSX_OS) rmdir(lockDir.c_str()); #else BOOL retStatus = RemoveDirectoryA(lockDir.c_str()); assert(retStatus == TRUE); #endif }
void dir_rmdir(const std::string &name) { #ifdef _MSC_VER BOOL r = RemoveDirectoryA(name.c_str()); internal_assert(r != 0) << "Unable to remove dir: " << name << ":" << GetLastError() << "\n"; #else int r = ::rmdir(name.c_str()); internal_assert(r == 0) << "Unable to remove dir: " << name << "\n"; #endif }
static void test_AdvInstallFile(void) { HRESULT hr; HMODULE hmod; char CURR_DIR[MAX_PATH]; char destFolder[MAX_PATH]; hmod = LoadLibrary("setupapi.dll"); if (!hmod) { skip("setupapi.dll not present\n"); return; } FreeLibrary(hmod); GetCurrentDirectoryA(MAX_PATH, CURR_DIR); lstrcpyA(destFolder, CURR_DIR); lstrcatA(destFolder, "\\"); lstrcatA(destFolder, "dest"); createTestFile("source.txt"); /* try invalid source directory */ hr = pAdvInstallFile(NULL, NULL, "source.txt", destFolder, "destination.txt", 0, 0); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %d\n", hr); ok(!DeleteFileA("dest\\destination.txt"), "Expected dest\\destination.txt to not exist\n"); /* try invalid source file */ hr = pAdvInstallFile(NULL, CURR_DIR, NULL, destFolder, "destination.txt", 0, 0); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %d\n", hr); ok(!DeleteFileA("dest\\destination.txt"), "Expected dest\\destination.txt to not exist\n"); /* try invalid destination directory */ hr = pAdvInstallFile(NULL, CURR_DIR, "source.txt", NULL, "destination.txt", 0, 0); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %d\n", hr); ok(!DeleteFileA("dest\\destination.txt"), "Expected dest\\destination.txt to not exist\n"); /* try copying to nonexistent destination directory */ hr = pAdvInstallFile(NULL, CURR_DIR, "source.txt", destFolder, "destination.txt", 0, 0); ok(hr == S_OK, "Expected S_OK, got %d\n", hr); ok(DeleteFileA("dest\\destination.txt"), "Expected dest\\destination.txt to exist\n"); /* native windows screws up if the source file doesn't exist */ /* test AIF_NOOVERWRITE behavior, asks the user to overwrite if AIF_QUIET is not specified */ createTestFile("dest\\destination.txt"); hr = pAdvInstallFile(NULL, CURR_DIR, "source.txt", destFolder, "destination.txt", AIF_NOOVERWRITE | AIF_QUIET, 0); ok(hr == S_OK, "Expected S_OK, got %d\n", hr); ok(DeleteFileA("dest\\destination.txt"), "Expected dest\\destination.txt to exist\n"); ok(RemoveDirectoryA("dest"), "Expected dest to exist\n"); DeleteFileA("source.txt"); }
static BOOL WINAPI fallbackRemoveDirectoryW(LPCWSTR dname) { BOOL retval = 0; const int buflen = (int)(wStrLen(dname) + 1); char *cpstr = (char *)__PHYSFS_smallAlloc(buflen); WideCharToMultiByte(CP_ACP, 0, dname, buflen, cpstr, buflen, NULL, NULL); retval = RemoveDirectoryA(cpstr); __PHYSFS_smallFree(cpstr); return(retval); } /* fallbackRemoveDirectoryW */
__private_extern__ Boolean _CFRemoveDirectory(const char *path) { #if DEPLOYMENT_TARGET_WINDOWS || 0 return RemoveDirectoryA(path); #else int no_hang_fd = open("/dev/autofs_nowait", 0); int ret = ((rmdir(path) == 0) ? true : false); close(no_hang_fd); return ret; #endif }
PRInt32 _PR_MD_RMDIR(const char *name) { if (RemoveDirectoryA(name)) { return 0; } else { _PR_MD_MAP_RMDIR_ERROR(GetLastError()); return -1; } }
static void tear_down_case_test(const char *testdir) { int ret; char buf[MAX_PATH]; sprintf(buf, "%s\\%s", testdir, "TesT"); ret = DeleteFileA(buf); ok(ret || (GetLastError() == ERROR_PATH_NOT_FOUND), "Failed to rm %s, error %d\n", buf, GetLastError()); RemoveDirectoryA(testdir); }
void removeDirectoryHelper(LPSTR dir, int location) { DWORD dwAtt = GetFileAttributesA(dir); if (( dwAtt != INVALID_FILE_ATTRIBUTES ) && ( dwAtt & FILE_ATTRIBUTE_DIRECTORY) ) { if(!RemoveDirectoryA(dir)) { Fail("ERROR: Failed to remove Directory [%s], Error Code [%d], location [%d]\n", dir, GetLastError(), location); } } }
/* Remove the given test directory and the attribute test files, if any */ static void tear_down_attribute_test(const char *testdirA) { int i; for (i=0; testfiles[i].name; i++) { int ret; char buf[MAX_PATH]; if (strcmp(testfiles[i].name, ".") == 0 || strcmp(testfiles[i].name, "..") == 0) continue; sprintf(buf, "%s\\%s", testdirA, testfiles[i].name); if (testfiles[i].attr & FILE_ATTRIBUTE_DIRECTORY) { ret = RemoveDirectoryA(buf); ok(ret || (GetLastError() == ERROR_PATH_NOT_FOUND), "Failed to rmdir %s, error %d\n", buf, GetLastError()); } else { ret = DeleteFileA(buf); ok(ret || (GetLastError() == ERROR_PATH_NOT_FOUND), "Failed to rm %s, error %d\n", buf, GetLastError()); } } RemoveDirectoryA(testdirA); }
static BOOL delete_pf( const char *rel_path, BOOL is_file ) { char path[MAX_PATH]; strcpy( path, PROG_FILES_DIR ); strcat( path, "\\" ); strcat( path, rel_path ); if (is_file) return DeleteFileA( path ); else return RemoveDirectoryA( path ); }
static BOOL delete_pf(const CHAR *rel_path, BOOL is_file) { CHAR path[MAX_PATH]; lstrcpyA(path, PROG_FILES_DIR); lstrcatA(path, "\\"); lstrcatA(path, rel_path); if (is_file) return DeleteFileA(path); else return RemoveDirectoryA(path); }
void FileImpl::removeImpl() { poco_assert (!_path.empty()); if (isDirectoryImpl()) { if (RemoveDirectoryA(_path.c_str()) == 0) handleLastErrorImpl(_path); } else { if (DeleteFileA(_path.c_str()) == 0) handleLastErrorImpl(_path); } }