I found an example on msdn:

My.Computer.FileSystem.WriteAllText("C:\TestFolder1\test.txt", "This is new text to be added.", False) 

If instead of the full path specify "test.txt" - there is no error, the file is saved somewhere. The question is, what is the full path and is there a rule for forming the path when specifying only the file name?

  • What is the full path and is there a rule for forming the path when specifying only the file name? The current path on the current device. See My.Computer.FileSystem.CurrentDirectory This is probably the current program launch directory, but not a fact ... - Akina
  • The file will be saved in the program directory, in the Debug / Release folder. Assuming the folder is on the desktop, then the path will be C:\Users\user\Desktop\ConsoleApp\ConsoleApp\bin\Debug\ваш_файл - dmepty am
  • @dmepty is not at all necessary - Pavel Mayorov
  • one
    Your path in the code is incorrectly specified - slashes are not escaped - PashaPash
  • one
    ))) Well, I'm not that stupid - Alexander Puzanov

1 answer 1

If only the file name is specified, the file will be created in the current directory.

The current directory can be any.

When the application is launched, the studio sets as the current directory the one in which the binaries are located.

When started from the command line, the current directory will be the one in which the user was on the command line.

When you start from under something else - the current directory is set completely at the discretion of the creators of this "other".

If you want to get the file in a specific directory - specify the full path.

  • If only the file name is specified, the file will be created in the current directory. Add - the current disk. He, too, can be any of the existing, and at any time can be changed. - Akina