【发布时间】:2012-09-17 15:10:44
【问题描述】:
std::wstring inxmpath ( L"folder" );
HANDLE hFind;
BOOL bContinue = TRUE;
WIN32_FIND_DATA data;
hFind = FindFirstFile(inxmpath.c_str(), &data);
// If we have no error, loop through the files in this dir
int counter = 0;
while (hFind && bContinue) {
std::wstring filename(data.cFileName);
std::string fullpath = "folder/";
fullpath += (const char* )filename.c_str();
if(remove(fullpath.c_str())!=0) return error;
bContinue = FindNextFile(hFind, &data);
counter++;
}
FindClose(hFind); // Free the dir
我不明白为什么它不起作用,我认为它与 wstring 和 string 之间的转换有关,但我不确定。我有一个包含一些 .txt 文件的文件夹,我需要使用 C++ 删除所有这些文件。里面没有文件夹什么都没有。这有多难?
【问题讨论】:
-
您是否尝试将
inxmpath设置为绝对文件夹路径? -
.exe 和“文件夹”在同一个文件夹中。如果是这种情况,我不确定是否需要这样做。
-
“不起作用”没有帮助。您观察到什么与您的预期相比,您已经尝试解决什么问题?
标签: c++ winapi directory delete-file