mkdir, rmdir

This commit is contained in:
David Rose 2010-03-02 22:41:08 +00:00
parent 88552b956c
commit 1a02e76c28
2 changed files with 51 additions and 4 deletions

View File

@ -2576,9 +2576,9 @@ make_dir() const {
Filename component(dirname.substr(0, slash));
string os_specific = component.to_os_specific();
#ifndef WIN32_VC
mkdir(os_specific.c_str(), 0777);
::mkdir(os_specific.c_str(), 0777);
#else
mkdir(os_specific.c_str());
::mkdir(os_specific.c_str());
#endif
slash = dirname.find('/', slash + 1);
}
@ -2587,9 +2587,54 @@ make_dir() const {
Filename component(dirname);
string os_specific = component.to_os_specific();
#ifndef WIN32_VC
int result = mkdir(os_specific.c_str(), 0777);
int result = ::mkdir(os_specific.c_str(), 0777);
#else
int result = mkdir(os_specific.c_str());
int result = ::mkdir(os_specific.c_str());
#endif
return (result == 0);
}
////////////////////////////////////////////////////////////////////
// Function: Filename::mkdir
// Access: Published
// Description: Creates the directory named by this filename. Unlike
// make_dir(), this assumes that the Filename contains
// the directory name itself. Also, parent directories
// are not automatically created; this function fails if
// any parent directory is missing.
////////////////////////////////////////////////////////////////////
bool Filename::
mkdir() const {
string os_specific = to_os_specific();
#ifndef WIN32_VC
int result = ::mkdir(os_specific.c_str(), 0777);
#else
int result = ::mkdir(os_specific.c_str());
#endif
return (result == 0);
}
////////////////////////////////////////////////////////////////////
// Function: Filename::rmdir
// Access: Published
// Description: The inverse of mkdir(): this removes the directory
// named by this Filename, if it is in fact a directory.
////////////////////////////////////////////////////////////////////
bool Filename::
rmdir() const {
string os_specific = to_os_specific();
int result = ::rmdir(os_specific.c_str());
#ifdef WIN32
if (result != 0) {
// Windows may require the directory to be writable before we can
// remove it.
chmod(os_specific.c_str(), 0777);
result = ::rmdir(os_specific.c_str());
}
#endif
return (result == 0);

View File

@ -203,6 +203,8 @@ PUBLISHED:
bool copy_to(const Filename &other) const;
bool make_dir() const;
bool mkdir() const;
bool rmdir() const;
// Comparison operators are handy.
INLINE bool operator == (const string &other) const;