判断标题文件是否存在,标题不存在则重命名Log文件为标题,存在则删除之后再重命名

include <stdio.h>

include

include <direct.h>

include <io.h>

using namespace std;

int main()
{

char MAC[256] = "123";
char file_01[256];
sprintf_s(file_01, ".\\Log\\%s.txt", MAC);
std::string prefix = file_01;
if (_access(prefix.c_str(), 0) == -1)	//如果文件夹不存在
{
	char file[256];
	sprintf_s(file, "rename .\\Log\\Log.txt %s.txt", MAC);
	system(file);
}
else {
	char file_02[256];
	sprintf_s(file_02, "rm -rf .\\Log\\%s.txt", MAC);
	system(file_02);
	sprintf_s(file_02, "rename .\\Log\\Log.txt %s.txt", MAC);
	system(file_02);

}


return 0;

}

posted @ 2021-06-24 09:43  江南王小帅  阅读(89)  评论(0)    收藏  举报