VC++ 创建删除多级目录源代码
2010-11-22 22:57
363 查看
//创建多级目录 BOOL MakeDirectory(CString dd) { HANDLE fFile; // File Handle WIN32_FIND_DATA fileinfo; // File Information Structure CStringArray m_arr; // CString Array to hold Directory Structures BOOL tt; // BOOL used to test if Create Directory was successful int x1 = 0; // Counter CString tem = ""; // Temporary CString Object fFile = FindFirstFile(dd,&fileinfo); // if the file exists and it is a directory if(fileinfo.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY) { // Directory Exists close file and return FindClose(fFile); return TRUE; } m_arr.RemoveAll(); for(x1 = 0; x1 < dd.GetLength(); x1++ ) // Parse the supplied CString Directory String { if(dd.GetAt(x1) != '//') // if the Charachter is not a / tem += dd.GetAt(x1); // add the character to the Temp String else { m_arr.Add(tem); // if the Character is a / tem += "//"; // Now add the / to the temp string } if(x1 == dd.GetLength()-1) // If we reached the end of the String m_arr.Add(tem); } // Close the file FindClose(fFile); // Now lets cycle through the String Array and create each directory in turn for(x1 = 1; x1 < m_arr.GetSize(); x1++) { tem = m_arr.GetAt(x1); tt = CreateDirectory(tem,NULL); // If the Directory exists it will return a false if(tt) SetFileAttributes(tem,FILE_ATTRIBUTE_NORMAL); // If we were successful we set the attributes to normal } // Now lets see if the directory was successfully created fFile = FindFirstFile(dd,&fileinfo); m_arr.RemoveAll(); if(fileinfo.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY) { // Directory Exists close file and return FindClose(fFile); return TRUE; } else { // For Some reason the Function Failed Return FALSE FindClose(fFile); return FALSE; } } //删除多级目录 BOOL DeleteDirectory(char *DirName)//如删除 DeleteDirectory("c://aaa") { CFileFind tempFind; char tempFileFind[MAX_PATH]; sprintf(tempFileFind,"%s//*.*",DirName); BOOL IsFinded=(BOOL)tempFind.FindFile(tempFileFind); while(IsFinded) { IsFinded=(BOOL)tempFind.FindNextFile(); if(!tempFind.IsDots()) { char foundFileName[MAX_PATH]; strcpy(foundFileName,tempFind.GetFileName().GetBuffer(MAX_PATH)); if(tempFind.IsDirectory()) { char tempDir[MAX_PATH]; sprintf(tempDir,"%s//%s",DirName,foundFileName); DeleteDirectory(tempDir); } else { char tempFileName[MAX_PATH]; sprintf(tempFileName,"%s//%s",DirName,foundFileName); DeleteFile(tempFileName); } } } tempFind.Close(); if(!RemoveDirectory(DirName)) { MessageBox(0,"删除目录失败!","警告信息",MB_OK);//比如没有找到文件夹,删除失败,可把此句删除 return FALSE; } return TRUE; } |
相关文章推荐
- 【VC编程技巧】文件☞2.6Windows上多级目录的创建和删除
- vc 一次创建多级目录
- 嵌套删除多级目录, 删除单级目录, 创建多级目录, 复制文件
- 创建删除多级目录
- 两个自己函数创建目录和删除目录,考虑了多级目录的情况
- 在VC中运用mkdir函数创建多级目录
- 使用VC创建多级目录
- VC小技巧--创建多级目录
- VC创建多级目录
- VC创建多级目录
- node同步创建多级目录和删除多级目录
- VC小技巧--创建多级目录
- VS 2008 创建、删除多级目录的方法 以及给文件夹增加隐藏属性
- 创建_中间/多级/嵌套_目录/文件夹 (Visual C++ 源代码)| Create intermediate directory (Visual C++ source code)
- vc创建多级目录
- vc 用mkdir 创建多级目录
- [VC/MFC]删除文件夹(非空目录)及其中所有文件的源代码
- 创建多级目录
- 创建、删除、复制文件夹及其子文件;找出某个目录下的所有文件名 .NET
- Unity 本地文件夹 目录查找,判断有否 没有创建 有删除。