我正在开发一个跟踪文件夹中操作的程序,并将它们存储在文本文件中,并在另一个目录中复制更改。程序从Logfile.txt
读取执行的操作,并将操作结果存储在ProcessLog.txt
如果文件夹中发生删除操作,则操作将存储在Logfile.txt
DEL
F:\somefolder\something.txt
每行末尾有\n
。我在另一个类似的目录中运行此代码以自动删除文件
std::ifstream Restfile("F:\\Logfile.txt");
std::ofstream Test("F:\\ProcessLog.txt");
while(!Restfile.eof())
{
std::string Action;
std::getline(Restfile, Action);
if(Action.compare("DEL")==0)
{
std::string Directory;
std::getline(Restfile, Directory);
//============================
Test<<"Deleting "<<Directory<<"\n";
//============================
std::wstring Directory_wstr( Directory.begin(), Directory.end() );
if(DeleteFileW(Directory_wstr.c_str()))
Test<<"Delete Success\n";
else
Test<<"Delete failure\n";
}
}
//proper closing statements
我将Delete Success
存储在ProcessLog.txt
中,这意味着该功能已成功执行,但该文件仍保留在目录中并且已被删除