#define BOOST_FILESYSTEM_VERSION 3 #ifndef UNICODE # define UNICODE #endif #include #include #include #include #include #include #include // standard POSIX header for mkdir #include // actual header for mkdir :) #include using namespace std; int main(int argc, char const *argv[]) try { int iRetCode = EXIT_SUCCESS; if (argc > 2) { cout << "Attempts to delete specified directory using boost::filesystem::remove_all()\n"; cout << "Syntax:\n"; cout << "\t" << argv[0] << " dirname\n"; cout << endl; iRetCode = EXIT_FAILURE; } else { if (argc == 2) { boost::filesystem::remove_all(argv[1]); iRetCode = EXIT_SUCCESS; } else { char const *tmp_dir = getenv("TMP"); if (tmp_dir == NULL) tmp_dir = getenv("TEMP"); if (tmp_dir) { int iCode = mkdir((string(tmp_dir) + "/v3_dir").c_str()); if (iCode == 0) mkdir((string(tmp_dir) + "/v3_dir/dirname").c_str()); if (iCode == 0) mkdir((string(tmp_dir) + "/v3_dir/dirnam2").c_str()); if (iCode == 0) mkdir((string(tmp_dir) + "/v3_dir/dirnam3").c_str()); else throw runtime_error ( string("Failed to create temporary directories for test.\n") + strerror(errno) ); TCHAR szTempDir[_MAX_PATH]; // Microsoft has _MAX_PATH in string strTempDir = tmp_dir; strTempDir += "/v3_dir"; TCHAR *pCh = szTempDir; string::const_iterator it = strTempDir.begin(); while ( it != strTempDir.end() && pCh < szTempDir + sizeof szTempDir / sizeof szTempDir[0] - 1 ) { *pCh++ = *it++; } *pCh = _T('\0'); boost::filesystem::remove_all(szTempDir); iRetCode = EXIT_SUCCESS; } else throw runtime_error("TEMP or TMP not set."); } } } catch(exception const &ex) { cerr << "Application error." << endl; cerr << ex.what() << endl; return EXIT_FAILURE; } catch(...) { cerr << "Application error."; return EXIT_FAILURE; }