DirectoryInfo dir = new DirectoryInfo(Directory.GetCurrentDirectory()); string s = @"C:\"; dir.MoveTo(s); 

Text in s for example. Whichever path is inserted, the exception still flies.

An exception:

"The process cannot access the file because the file is being used by another process."


What's wrong? Like the simplest code.



UPD 03/24/16. 17.45.

If someone needs, I can put the search algorithm up in folders.
Searches the current folder for the desired folder / file / files with the specified extension. If not found, it rises to a higher level and searches there, even higher, and so on. Optionally - search in subfolders, maximum number of levels of "lifting" up, the name of the desired directory, file search mask (one file or files with a specified extension), folder start searching.
At the exit - the path to the found folder. Search lazy - to the first found folder in which there are the required files.

  • 6
    An application is running from the current folder, so you cannot move it. At least - this is what comes to mind first. - Monk
  • @Monk post as answer. - andreycha

1 answer 1

An application is running from the current folder, so you cannot move it.

At least - this is what comes to mind first.

  • Directory.GetCurrentDirectory () does return the working directory of the application, so that’s all true. Confirmation here msdn.microsoft.com/ru-ru/library/… . Of course, if the current directory is not changed manually. - rdorn
  • Thank you, it came to me for a long time. I thought DirectoryInfo is something like a pointer to a folder that you can change as you like. - Max
  • @rdorn, therefore, when starting up from some FAR, you can suddenly get another folder, sometimes it's funny so you can find the configs and logs in other folders. - Monk