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和「文件夾」位於相同的文件夾中。如果情況屬實,我不確定是否需要這樣做。 – ksm001
「不起作用」沒有幫助。你在觀察什麼,你期望什麼,你已經試圖解決它? – tenfour