C++创建和删除文件夹的方法
一、说明
下面的测试代码在linux下运行通过
二、测试代码
1、boost库和linux下的库函数
#include <iostream>
#include "boost/filesystem.hpp"
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
using namespace std;
int main(int argc, char *argv[])
{
const string exeFile = argv[0];
cout << "exeFile:" << exeFile << endl;
boost::filesystem::path tempExeFile(exeFile);
const string exePath = tempExeFile.parent_path().string();
cout << "exePath:" << exePath << endl;
string tempDir = (tempExeFile.parent_path()/"tempFile").string();
if(!boost::filesystem::exists(tempDir))
{
bool flag = boost::filesystem::create_directory(tempDir);
if(flag)
{
cout << "tempDir:" << tempDir << endl;
cout