9 #define _WIN32_WINNT 0x0501
17 #define BUFSIZE MAX_PATH
19 std::vector<DirListNode> GetDirListing(std::string pathstring)
21 std::vector<DirListNode> listing;
23 WIN32_FIND_DATA FindFileData;
24 HANDLE hFind = INVALID_HANDLE_VALUE;
29 DirSpec = (LPTSTR) malloc (BUFSIZE);
33 printf( "Insufficient memory available\n" );
38 // Check that the input is not larger than allowed.
39 if (pathstring.size() > (BUFSIZE - 2))
41 _tprintf(TEXT("Input directory is too large.\n"));
46 //_tprintf (TEXT("Target directory is %s.\n"), pathstring.c_str());
48 sprintf(DirSpec, "%s", (pathstring + "\\*").c_str());
50 // Find the first file in the directory.
51 hFind = FindFirstFile(DirSpec, &FindFileData);
53 if (hFind == INVALID_HANDLE_VALUE)
55 _tprintf (TEXT("Invalid file handle. Error is %u.\n"),
62 node.name = FindFileData.cFileName;
63 node.dir = FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
64 listing.push_back(node);
66 // List all the other files in the directory.
67 while (FindNextFile(hFind, &FindFileData) != 0)
70 node.name = FindFileData.cFileName;
71 node.dir = FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
72 listing.push_back(node);
75 dwError = GetLastError();
77 if (dwError != ERROR_NO_MORE_FILES)
79 _tprintf (TEXT("FindNextFile error. Error is %u.\n"),
90 if(retval != 0) listing.clear();
92 //for(unsigned int i=0; i<listing.size(); i++){
93 // std::cout<<listing[i].name<<(listing[i].dir?" (dir)":" (file)")<<std::endl;
99 bool CreateDir(std::string path)
101 bool r = CreateDirectory(path.c_str(), NULL);
104 if(GetLastError() == ERROR_ALREADY_EXISTS)
109 bool PathExists(std::string path)
111 return (GetFileAttributes(path.c_str()) != INVALID_FILE_ATTRIBUTES);
118 #include <sys/types.h>
121 #include <sys/stat.h>
123 std::vector<DirListNode> GetDirListing(std::string pathstring)
125 std::vector<DirListNode> listing;
129 if((dp = opendir(pathstring.c_str())) == NULL) {
130 //std::cout<<"Error("<<errno<<") opening "<<pathstring<<std::endl;
134 while ((dirp = readdir(dp)) != NULL) {
135 if(dirp->d_name[0]!='.'){
137 node.name = dirp->d_name;
138 if(dirp->d_type == DT_DIR) node.dir = true;
139 else node.dir = false;
140 listing.push_back(node);
148 bool CreateDir(std::string path)
150 int r = mkdir(path.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
157 // If already exists, return true
164 bool PathExists(std::string path)
167 return (stat(path.c_str(),&st) == 0);
172 #include "boost/filesystem/operations.hpp"
173 namespace bfsys = boost::filesystem;
175 std::vector<DirListNode> GetDirListing(std::string pathstring)
177 std::vector<DirListNode> listing;
179 bfsys::path path(pathstring);
181 if( !exists( path ) ) return listing;
183 bfsys::directory_iterator end_itr; // default construction yields past-the-end
184 for( bfsys::directory_iterator itr( path ); itr != end_itr; ++itr ){
186 node.name = itr->leaf();
187 node.dir = is_directory(*itr);
188 listing.push_back(node);
194 bool CreateDir(std::string path)
196 std::cout<<"CreateDir not implemented in boost"<<std::endl;