Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rename to folder with tilde symbol

Tags:

c#

rename

tilde

I know the method Directory.Move(source, destination) to rename a folder. But when I rename the desitnation folder with the ~ symbol at the begin, there is error.

System.NotSupportedException: The given path's format is not supported.

Here is my code:

string oldFolderPath = @"C:\Old";
string newFolderPath = "~" + oldFolderPath;
Directory.Move(oldFolderPath, newFolderPath);

In the System.IO.Path.InvalidPathChars, the following characters are invalid: " < > |

It does not list tilde symbol, so how can I do? Thank you very much.

like image 295
quyleanh Avatar asked Dec 04 '25 23:12

quyleanh


1 Answers

Tilde is perfectly valid in a folder name. Your code sample doesn't show what value demoPath has but, since tilde is valid in the folder name, you're probably doing something like appending it to the start of the path and not where you intended to.

E.g. not like this: ~C:\Old but C:\~Old.

like image 55
Owen Pauling Avatar answered Dec 06 '25 13:12

Owen Pauling