windows下清空目录下指定文件函数
2011-10-18 11:23
761 查看
#include <iostream>
#include <Windows.h>
int _tmain(int argc, _TCHAR* argv[])
{
std::wstring wstrDir = L"E:\\测试\\*.png";
WIN32_FIND_DATA wfd;
HANDLE hFind = FindFirstFile(wstrDir.c_str(), &wfd);
// 如果没有找到或查找失败
if (hFind == INVALID_HANDLE_VALUE)
{
return 0;
}
do
{
size_t found = wstrDir.rfind(L"\\");
size_t len = wstrDir.size();
if (found!=0)
wstrDir.replace (found + 1,wstrDir.size() - found - 1,wfd.cFileName);
// 对文件进行操作
DeleteFile(wstrDir.c_str());
}while (FindNextFile(hFind, &wfd));
FindClose(hFind); // 关闭查找句柄
return 0;
}
#include <Windows.h>
int _tmain(int argc, _TCHAR* argv[])
{
std::wstring wstrDir = L"E:\\测试\\*.png";
WIN32_FIND_DATA wfd;
HANDLE hFind = FindFirstFile(wstrDir.c_str(), &wfd);
// 如果没有找到或查找失败
if (hFind == INVALID_HANDLE_VALUE)
{
return 0;
}
do
{
size_t found = wstrDir.rfind(L"\\");
size_t len = wstrDir.size();
if (found!=0)
wstrDir.replace (found + 1,wstrDir.size() - found - 1,wfd.cFileName);
// 对文件进行操作
DeleteFile(wstrDir.c_str());
}while (FindNextFile(hFind, &wfd));
FindClose(hFind); // 关闭查找句柄
return 0;
}
相关文章推荐
- 两个delphi下遍历指定目录下指定类型文件的函数
- windows中操作文件和目录的函数
- delphi遍历指定目录下指定类型文件的函数
- php清空(删除)指定目录下的文件,不删除目录文件夹的实现代码
- 遍历指定目录下指定类型文件的函数
- windows使用命令行快速删除当前目录下所有指定后缀的文件
- Windows中将生成的文件复制到指定目录中
- php使用glob函数快速查询指定目录文件的方法
- windows 定时清理指定目录文件bat
- php使用glob函数快速查询指定目录文件的方法
- 常用函数之指定目录下查询文件
- Windows 如何在创建指定目录以及复制文件
- 两个delphi下遍历指定目录下指定类型文件的函数
- 利用FindFirstFile(),FindNextFile()函数历遍指定目录的所有文件
- MFC获取指定目录下的所有文件函数
- 利用Windows Service,定时监控某一目录,发现新文件后自动上传到指定web服务器
- Python:编写函数,能在当前目录以及子目录下查找文件名包含指定字符串的文件,并打印出完整路径
- php下实现在指定目录搜索指定类型文件的函数
- Windows文件、目录操作函数
- php清空(删除)指定目录下的文件,不删除目录文件夹的实现代码