c++ - Windows: File rename and directory iteration clash -


I am using boost :: filesystem to rename a file like this:

  boost :: filesystem :: rename (tmpFileName, targetFile);  

tmpFileName / targetFile type :: boost :: filsystem :: path

While doing this, I use this code on a directory in another thread :

  directory_iterator end_itr; (Directory_iterator itr (dirInfoPath); itr! = End_itr; ++ IRR) {path currentPath = itr-> Path (); If (is_directory (itr-> (state ())) {// Skip Directory} Other {std :: string file_name = currentPath.leaf (); If (! Boost :: algorithm :: starts_with (file_name, "new") & amp;! Boost :: algorithm :: begin_with (file_name, "finished") and boost :: algorithm :: ends_with (file_name, " .info ")) {// The saved filename is correct in some variable returns; }}}  

When this code is executed, I get an exception to rename:

  boost :: filesystem :: rename: process File can not be accessed because it is being used by another process  

Is it possible that the recurrence and renaming operations collide, because they both use Directory Inodes, Or do I have some more problems?

The code you provided does not have any file open operation, so it lock file. You iterate over the directory and rename the file , right? It is therefore possible that this file is actually used by another application such as file viewer or something else, this is a fairly common error or you have opened it in your app elsewhere


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -