Why am I getting the error "This path format is not supported"

I cannot rename a file located in (D-drive) using C #. I get an error

Exception Details: System.NotSupportedException: The specified format path is not supported.

everytime.

I use

string oldfilename = @"D:\abc\file.txt";
string newfilename = @"D:\abc\tree.txt";
System.IO.File.Move(oldfilename, newfilename);

but I get an error in the last line. I also tried changing the first 2 lines to

string oldfilename = "D:\\abc\\file.txt";
string newfilename = "D:\\abc\\tree.txt";

I also ensured the existence of the file.txt file. Tried to use a different location.

I also tried to read the contents of file.txt, but I get the same error. I searched all the questions about SO but no luck, I could solve this problem. I think there is some problem with ":" which I use after the drive letter when specifying the path. Please guide me.

+4
3

, ! (). , "file.txt" .

string oldfilename = "file.txt";
string newfilename = "tree.txt";
System.IO.File.Move(oldfilename, newfilename);

! ( ), .

0

:

 My.Computer.Filesystem.RenameFile("D:\file.txt", "tree.txt")
0

, :

        string oldfilename = "C:\\Users\\User\\Downloads\\WorkTemp\\file.txt";
        string newfilename = "C:\\Users\\User\\Downloads\\WorkTemp\\file2.txt";
        System.IO.File.Move(oldfilename, newfilename);


        string oldfilename = @"C:\Users\User\Downloads\WorkTemp\file1.txt";
        string newfilename = @"C:\Users\User\Downloads\WorkTemp\file2.txt";
        System.IO.File.Move(oldfilename, newfilename);

: http://referencesource.microsoft.com/#mscorlib/system/io/filestream.cs#749

NotSupportedException will be thrown if the index: in your path is in third position or later. (One would expect: to be the second character). Are you sure that your source does not use zero-width characters or other similar unicode frauds? from answer

-2
source

Source: https://habr.com/ru/post/1608012/


All Articles