Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Moved file without specifying path

I just ran

File.Move(@"C:\sub1\file.xml", "file" + ".XMl"));

The file did dissappear from C:\sub1. No error was thrown. Did the file go somewhere?

like image 821
EllieK Avatar asked Oct 26 '25 08:10

EllieK


2 Answers

When directory is not specified, current one is used:

https://msdn.microsoft.com/en-us/library/system.io.file.move(v=vs.110).aspx

The sourceFileName and destFileName arguments can include relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see GetCurrentDirectory.

  Environment.CurrentDirectory = @"C:\Test";

  // C:\sub1\file.xml will be moved to C:\Test\file.XMl 
  File.Move(@"C:\sub1\file.xml", "file" + ".XMl"));
like image 122
Dmitry Bychenko Avatar answered Oct 28 '25 21:10

Dmitry Bychenko


It moved to the app working directory. Usually it is where executable file located

like image 30
Alexander Egorov Avatar answered Oct 28 '25 22:10

Alexander Egorov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!