Commit f28202b15e567f7e19f00496e551da079e7e6148
1 parent
f92397d2
fixed OS interop problems with filename
Showing
1 changed file
with
13 additions
and
14 deletions
Show diff stats
stim/parser/filename.h
... | ... | @@ -43,18 +43,13 @@ protected: |
43 | 43 | |
44 | 44 | bool absolute; //filename is an absolute path |
45 | 45 | |
46 | - //replace any incorrect dividers with the appropriate version for the OS | |
47 | - std::string parse_div(std::string s) { | |
48 | - #ifdef _WIN32 | |
49 | - std::replace( s.begin(), s.end(), '/', '\\'); | |
50 | - #else | |
51 | - std::replace( s.begin(), s.end(), '\\', '/'); | |
52 | - #endif | |
53 | - | |
46 | + //replaces win32 dividers with the Linux standard | |
47 | + std::string unix_div(std::string s) { | |
48 | + std::replace( s.begin(), s.end(), '\\', '/'); | |
54 | 49 | return s; |
55 | 50 | } |
56 | 51 | |
57 | - //parse the file name (prefix and extension) | |
52 | + //break up a filename into a prefix and extension | |
58 | 53 | void parse_name(std::string fname){ |
59 | 54 | |
60 | 55 | //find the extension |
... | ... | @@ -70,6 +65,8 @@ protected: |
70 | 65 | //parse a file locator string |
71 | 66 | void parse(std::string loc){ |
72 | 67 | |
68 | + loc = unix_div(loc); | |
69 | + | |
73 | 70 | //determine the drive (if Windows) |
74 | 71 | drive = ""; |
75 | 72 | #ifdef _WIN32 |
... | ... | @@ -87,14 +84,14 @@ protected: |
87 | 84 | #endif |
88 | 85 | |
89 | 86 | //determine the file name |
90 | - std::string fname = loc.substr( loc.find_last_of(STIM_FILENAME_DIV) + 1 ); //find the file name (including extension) | |
87 | + std::string fname = loc.substr( loc.find_last_of('/') + 1 ); //find the file name (including extension) | |
91 | 88 | |
92 | 89 | //parse the file name |
93 | 90 | parse_name(fname); |
94 | 91 | |
95 | 92 | //find the directory hierarchy |
96 | - std::string dir = loc.substr(0, loc.find_last_of(STIM_FILENAME_DIV) + 1 ); | |
97 | - path = stim::parser::split(dir, STIM_FILENAME_DIV); | |
93 | + std::string dir = loc.substr(0, loc.find_last_of('/') + 1 ); | |
94 | + path = stim::parser::split(dir, '/'); | |
98 | 95 | } |
99 | 96 | |
100 | 97 | public: |
... | ... | @@ -210,6 +207,7 @@ public: |
210 | 207 | |
211 | 208 | //stim::filename file_path; |
212 | 209 | stim::filename filepath(dir_fname()); |
210 | + | |
213 | 211 | HANDLE hFind = INVALID_HANDLE_VALUE; |
214 | 212 | WIN32_FIND_DATAA FindFileData; |
215 | 213 | std::vector<stim::filename> file_list; |
... | ... | @@ -220,8 +218,9 @@ public: |
220 | 218 | printf ("Invalid file handle. Error is %u.\n", GetLastError()); |
221 | 219 | } |
222 | 220 | else { |
223 | - std::string file_name = FindFileData.cFileName; | |
224 | - stim::filename current_file(f_name(file_name)); | |
221 | + std::string file_name = FindFileData.cFileName; //get the file name | |
222 | + std::string file_path = dir(); | |
223 | + stim::filename current_file(file_path + file_name); | |
225 | 224 | file_list.push_back(current_file); |
226 | 225 | |
227 | 226 | // List all the other files in the directory. | ... | ... |