问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

RemoveDirectory() 怎么删除 非空目录啊

发布网友 发布时间:2022-05-02 04:28

我来回答

3个回答

热心网友 时间:2022-06-28 05:47

RemoveDirectory( )只能删除空目录,你可以用递归的办法先删除目录下的文件,然后再删除目录。如果不进行递归删除。你可以使用API函数SHFileOperation,它可以一次删除目录及其下面的子目录和文件。

热心网友 时间:2022-06-28 05:47

CString StrSourceFolder="C:\\1";
char SourceFolder[MAX_PATH+1]="";
strcpy(SourceFolder,StrSourceFolder);
SHFILEOPSTRUCT lpFile;
lpFile.hwnd=GetSafeHwnd();
lpFile.wFunc=FO_DELETE;
lpFile.pFrom=SourceFolder;
lpFile.pTo=NULL;
lpFile.fFlags=FOF_ALLOWUNDO;
lpFile.fAnyOperationsAborted=FALSE;
lpFile.hNameMappings=NULL;
lpFile.lpszProgressTitle=NULL;
int ReturnValue=SHFileOperation(&lpFile);
if(ReturnValue==0)
{
if(lpFile.fAnyOperationsAborted==TRUE)
MessageBox("删除文件夹的操作被取消","信息提示",MB_OK+MB_ICONWARNING);
else
MessageBox("删除文件夹操作成功","信息提示",MB_OK+MB_ICONWARNING);
}
else
MessageBox("删除文件夹操作失败","信息提示",MB_OK+MB_ICONEXCLAMATION);

热心网友 时间:2022-06-28 05:48

The RemoveDirectory function deletes an existing empty directory.

BOOL RemoveDirectory(

LPCTSTR lpPathName // address of directory to remove
);

Searching for Files and Changing File Attributes
The following example copies all text files in the current directory to a new directory of read-only files named \TEXTRO. Files in the new directory are changed to read only, if necessary.

The application uses the GetCurrentDirectory function to retrieve the current directory path. This function is also used to return to the current directory after changing to the \TEXTRO directory.

The application then creates the \TEXTRO directory by using the CreateDirectory function.

The application searches the current directory for all .TXT files by using the FindFirstFile and FindNextFile functions. Each .TXT file is copied to the \TEXTRO directory. After a file is copied, the GetFileAttributes function determines whether the file is read only. If the file is not read only, the application changes directories to \TEXTRO and converts the copied file to read only by using the SetFileAttributes function.

After all .TXT files in the current directory have been copied, the application closes the search handle by using the FindClose function.

WIN32_FIND_DATA FileData;
HANDLE hSearch;
DWORD dwAttrs;
char szDirPath[] = "c:\\TEXTRO\\";
char szNewPath[MAX_PATH];
char szHome[MAX_PATH];

BOOL fFinished = FALSE;

// Create a new directory.

if (!CreateDirectory(szDirPath, NULL))
{
ErrorHandler("Couldn't create new directory.");
}

// Start searching for .TXT files in the current directory.

hSearch = FindFirstFile("*.txt", &FileData);
if (hSearch == INVALID_HANDLE_VALUE)
{
ErrorHandler("No .TXT files found.");
}

// Copy each .TXT file to the new directory
// and change it to read only, if not already.

while (!fFinished)
{
lstrcpy(szNewPath, szDirPath);
lstrcat(szNewPath, FileData.cFileName);
if (CopyFile(FileData.cFileName, szNewPath, FALSE))
{
dwAttrs = GetFileAttributes(FileData.cFileName);
if (!(dwAttrs & FILE_ATTRIBUTE_READONLY))
{
SetFileAttributes(szNewPath,
dwAttrs | FILE_ATTRIBUTE_READONLY);
}
}
else
{
ErrorHandler("Couldn't copy file.");
}

if (!FindNextFile(hSearch, &FileData))
{
if (GetLastError() == ERROR_NO_MORE_FILES)
{
MessageBox(hwnd, "No more .TXT files.",
"Search completed.", MB_OK);
fFinished = TRUE;
}
else
{
ErrorHandler("Couldn't find next file.");
}
}
}

// Close the search handle.

if (!FindClose(hSearch))
{
ErrorHandler("Couldn't close search handle.");
}

Parameters

lpPathName

Points to a null-terminated string that specifies the path of the directory to be removed. The path must specify an empty directory, and the calling process must have delete access to the directory.

Return Values

If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.

See Also

CreateDirectory

The DeleteFile function deletes an existing file.

BOOL DeleteFile(

LPCTSTR lpFileName // pointer to name of file to delete
);

Parameters

lpFileName

Points to a null-terminated string that specifies the file to be deleted.

Return Values

If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

If an application attempts to delete a file that does not exist, the DeleteFile function fails.
Windows 95: The DeleteFile function deletes a file even if it is open for normal I/O or as a memory-mapped file. To prevent loss of data, close files before attempting to delete them.
Windows NT: The DeleteFile function fails if an application attempts to delete a file that is open for normal I/O or as a memory-mapped file.
To close an open file, use the CloseHandle function.

he FindFirstFile function searches a directory for a file whose name matches the specified filename. FindFirstFile examines subdirectory names as well as filenames.

HANDLE FindFirstFile(

LPCTSTR lpFileName, // pointer to name of file to search for
LPWIN32_FIND_DATA lpFindFileData // pointer to returned information
);

Parameters

lpFileName

Windows 95: Points to a null-terminated string that specifies a valid directory or path and filename, which can contain wildcard characters (* and ?). This string must not exceed MAX_PATH characters.
Windows NT: Points to a null-terminated string that specifies a valid directory or path and filename, which can contain wildcard characters (* and ?).
There is a default string size limit for paths of MAX_PATH characters. This limit is related to how the FindFirstFile function parses paths. An application can transcend this limit and send in paths longer than MAX_PATH characters by calling the wide (W) version of FindFirstFile and prepending "\\?\" to the path. The "\\?\" tells the function to turn off path parsing; it lets paths longer than MAX_PATH be used with FindFirstFileW. This also works with UNC names. The "\\?\" is ignored as part of the path. For example, "\\?\C:\myworld\private" is seen as "C:\myworld\private", and "
\\?\UNC\bill_g_1\hotstuff\coolapps" is seen as "\\bill_g_1\hotstuff\coolapps".

lpFindFileData

Points to the WIN32_FIND_DATA structure that receives information about the found file or subdirectory. The structure can be used in subsequent calls to the FindNextFile or FindClose function to refer to the file or subdirectory.

Return Values

If the function succeeds, the return value is a search handle used in a subsequent call to FindNextFile or FindClose.
If the function fails, the return value is INVALID_HANDLE_VALUE. To get extended error information, call GetLastError.

Remarks

The FindFirstFile function opens a search handle and returns information about the first file whose name matches the specified pattern. Once the search handle is established, you can use the FindNextFile function to search for other files that match the same pattern. When the search handle is no longer needed, close it by using the FindClose function.
This function searches for files by name only; it cannot be used for attribute-based searches.

The FindNextFile function continues a file search from a previous call to the FindFirstFile function.

BOOL FindNextFile(

HANDLE hFindFile, // handle to search
LPWIN32_FIND_DATA lpFindFileData // pointer to structure for data on found file
);

Parameters

hFindFile

Identifies a search handle returned by a previous call to the FindFirstFile function.

lpFindFileData

Points to the WIN32_FIND_DATA structure that receives information about the found file or subdirectory. The structure can be used in subsequent calls to FindNextFile to refer to the found file or directory.

Return Values

If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError. If no matching files can be found, the GetLastError function returns ERROR_NO_MORE_FILES.

Remarks

The FindNextFile function searches for files by name only; it cannot be used for attribute-based searches.
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
苹果电脑电池充不进电苹果电脑充不进去电是怎么回事 苹果电脑不充电没反应苹果电脑充电指示灯不亮充不了电怎么办 狗狗更加忠诚护家、善解人意,养一只宠物陪伴自己,泰迪能长多大... 描写泰迪狗的外形和特点的句子 国外留学有用吗 花钱出国留学有用吗 !这叫什么号 百万医疗赔付后是否可以续保 前一年理赔过医疗险还能续保吗? 医疗住院险理赔后还能购买吗? 为什么这里的rmdir删除不掉非空目录? 如何在DOS下删除文件夹不是空的子目录? win7 dos下怎么删除非空目录啊? 企业财务管理的内容包括哪些 财务管理有哪些内容 别人把我拉黑怎么解除 社保本子去哪里领 农村信用社手机银行帐户明细里的自输摘要是什么意思? 农业银行对账单的摘要是什么意思,而且会有出现一些英文大写字母代替,是不是备注这些钱是从哪里来的啊? 中国银行业务摘要是什么东西?怎么取消?求帮忙,谢谢。。 银行的定期存款摘要001代表什么意思 中国银行对账单摘要代码分别什么意思 银行明细摘要p5220321什么意思 交易摘要的定义是什么? 工商银行业务摘要居民什么意思 储蓄卡被北京*冻结一个月说是非法集资怎么解封,我去问银行也不知道具体情况,该怎么办? 银行卡被公安局冻结,多久可以恢复? 银行了被异地公安局刑侦大队冻结期限一个月,一个月会解冻吗? 苦瓜和洋葱混到一起炒肉有没有害处? 春天,孩子应多吃什么蔬菜? dos下删除非空文件夹 dos中想删除某个目录下的大量非空目录 如何在DOS中删除一文件下的所有非空的目录和子目录? 信用卡刷不出来显示交易失败 贵阳银行的移动pos机 不能刷贵阳银行的信用卡吗 贵阳银行信用卡综合不达标 贵阳银行信用卡两万的额度,后来有一万六的额度,全部刷完了逾期了三 爽爽bank软件里显示自己无可用信用卡是什么意思? 贵阳银行信用卡不设置交易密码可以刷卡消费吗 贵阳银行信用卡显示还款成功,里面一直没钱怎么回事? 交通事故第三者责任险指的是什么 大股东通过大宗交易减持公司股票股票跌吗? 交通事故强制责任险 为什么要用“请登录”,用"登录"不是更合实际情况吗? 赠与人去世之后赠与合同生效吗 赠与合同中的赠与人死亡怎么办 网址明明登录了账号为什么老是说请登录? 电视机上出现“您已登出,请登录”怎么办 笔记本电脑登录人人网时不停的出现“请登录”怎么办? 赠与人去世之后赠与合同是否能生效