What is the best way to get the name of a folder that does not exist?

What is the best way to get a string containing the name of a folder that I can be sure does n't exist ? That is, if I call DirectoryInfo.Existsfor a given path, it should return false.

EDIT: the reason is that I am writing a test to check for errors, the error tester checks to see if a path exists, so I aloud asked how best to get a path that does not exist.

+3
source share
8 answers

Name it after the GUID - just output invalid characters.

+9
source

, . , , , DirectoryInfo.Exists false, - - .

- , , .

+6

, , , , , . , :

        string path = Path.GetTempFileName();
        File.Delete(path);
        Directory.CreateDirectory(path);

, (.. /, - ).

+5

:

using System.IO;

string path = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());

( , , - )

+4

, , , .

: ? ?

0

- ? Guid.NewGuid, , , , .

0

, :

directoryName = Guid.NewGuid.ToSrtring();

Guid , 2 dirs .

0

GUID , (, /), , . , extreme :

string ParentPath = System.IO.Path.Combine(Environment.GetEnvironmentVariable("TEMP"), "MyAppName");
string UniquePath = System.IO.Path.Combine(ParentPath, Guid.NewGuid().ToString());
System.IO.Directory.CreateDirectory(UniquePath);
0

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


All Articles