From f28202b15e567f7e19f00496e551da079e7e6148 Mon Sep 17 00:00:00 2001 From: David Date: Thu, 4 Feb 2016 13:55:53 -0600 Subject: [PATCH] fixed OS interop problems with filename --- stim/parser/filename.h | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/stim/parser/filename.h b/stim/parser/filename.h index a5cbc9b..bb61bbc 100644 --- a/stim/parser/filename.h +++ b/stim/parser/filename.h @@ -43,18 +43,13 @@ protected: bool absolute; //filename is an absolute path - //replace any incorrect dividers with the appropriate version for the OS - std::string parse_div(std::string s) { - #ifdef _WIN32 - std::replace( s.begin(), s.end(), '/', '\\'); - #else - std::replace( s.begin(), s.end(), '\\', '/'); - #endif - + //replaces win32 dividers with the Linux standard + std::string unix_div(std::string s) { + std::replace( s.begin(), s.end(), '\\', '/'); return s; } - //parse the file name (prefix and extension) + //break up a filename into a prefix and extension void parse_name(std::string fname){ //find the extension @@ -70,6 +65,8 @@ protected: //parse a file locator string void parse(std::string loc){ + loc = unix_div(loc); + //determine the drive (if Windows) drive = ""; #ifdef _WIN32 @@ -87,14 +84,14 @@ protected: #endif //determine the file name - std::string fname = loc.substr( loc.find_last_of(STIM_FILENAME_DIV) + 1 ); //find the file name (including extension) + std::string fname = loc.substr( loc.find_last_of('/') + 1 ); //find the file name (including extension) //parse the file name parse_name(fname); //find the directory hierarchy - std::string dir = loc.substr(0, loc.find_last_of(STIM_FILENAME_DIV) + 1 ); - path = stim::parser::split(dir, STIM_FILENAME_DIV); + std::string dir = loc.substr(0, loc.find_last_of('/') + 1 ); + path = stim::parser::split(dir, '/'); } public: @@ -210,6 +207,7 @@ public: //stim::filename file_path; stim::filename filepath(dir_fname()); + HANDLE hFind = INVALID_HANDLE_VALUE; WIN32_FIND_DATAA FindFileData; std::vector file_list; @@ -220,8 +218,9 @@ public: printf ("Invalid file handle. Error is %u.\n", GetLastError()); } else { - std::string file_name = FindFileData.cFileName; - stim::filename current_file(f_name(file_name)); + std::string file_name = FindFileData.cFileName; //get the file name + std::string file_path = dir(); + stim::filename current_file(file_path + file_name); file_list.push_back(current_file); // List all the other files in the directory. -- libgit2 0.21.4