[Filesystem] File Rename issue
Hi, I have some trouble with a file renaming program i wrote. The program is supposed to recursively traverse a folders in search for a file, and rename the file to the name of the folder. The program, traverses all the folders successfully, but when i try the rename command i get the following compile error "error C2039: current_path is not a member of 'path', see declaration of path. c:\boost\include\boost-1_33_1\boost\filesystem\path.hpp I am aware that the current_path() function is not included in path.hpp however the object that i am trying to use it on is a directory _iterator and as such should work. I am new to all of this stuff, any advice would be appreciated, Below is the very non elegant source code with the problem highlighted close to the end of the code. int i=0; namespace fs = boost::filesystem; bool recursiveList(fs::path); int main() { fs::path fullPath("test2"); recursiveList(fullPath); std::cout<<"Number of files = "<<i<<"\n"; return 0; } bool recursiveList(fs::path givenPath) { char iteration=0; std::string directoryName="failed"; fs::directory_iterator end_iter; fs::directory_iterator start_iter(givenPath); fs::directory_iterator restart_Path(givenPath); int numberOfFiles=0; givenPath=fs::system_complete(givenPath); std::cout<<"The full path is: "<<givenPath.native_directory_string()<<"\n\n"; for (; start_iter!=end_iter; ++start_iter) { if ( fs::is_directory(*start_iter)) { std::cout<<start_iter->leaf()<<"[directory]\n\n"; directoryName=start_iter->leaf(); recursiveList(*start_iter); ; } else { std::cout<<start_iter->leaf()<<"[file]\n\n"; i++; numberOfFiles++; } } for (int j=0;j<numberOfFiles;j++,restart_Path++) { if(!fs::is_directory(*restart_Path)) { if (numberOfFiles==1) { std::cout<<"Multiple Files detected, attempting rename with iterations\n"; std::cout<<"Attempting Name Change...\n"; std::cout<<"Present Name: "<<restart_Path->leaf()<<"\n"; std::cout<<directoryName; //PROBLEM HERE!!!!! //***************************************************** fs::rename(restart_Path->current_path(),directoryName); //***************************************************** } } } return true; }
participants (1)
-
Andrei Danaila