EllieK
EllieK

Reputation: 273

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?

Upvotes: 4

Views: 231

Answers (3)

Dmitrii Bychenko
Dmitrii Bychenko

Reputation: 186668

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"));

Upvotes: 8

Alexander Egorov
Alexander Egorov

Reputation: 593

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

Upvotes: 3

Maksim Simkin
Maksim Simkin

Reputation: 9679

Yes, it's in your running folder.

Upvotes: 2

Related Questions