0

I use:

public const string WbPlanDirPath = "\\SavedWbPlans";

if (!Directory.Exists(WbPlanDirPath))
{
    System.IO.Directory.CreateDirectory(WbPlanDirPath);
}  

to create a directory. Although, it seems to work fine (no exceptions being thrown) I cannot find the folder/directory anywhere in the file system. Am I doing something wrong ?

Cemre Mengü
  • 18,062
  • 27
  • 111
  • 169

5 Answers5

2
"\\SavedWbPlans"

Notice the backslash at the very beginning. In the context of paths in Windows, this refers to the root of a drive.

So, the directory is very likely created on the root of your drive, depending where the working directory is.

For example, if the working directory is D:\Somewhere\in\the\drive\, it will be created as D:\SavedWbPlans.


If you are trying to create a directory in the same directory where the program is located at, use the following code instead:

string directory_of_program = Path.GetDirectoryName(Application.ExecutablePath);
string WbPlanDirPath = Path.Combine(directory_of_program, "SavedWbPlans");

if (!Directory.Exists(WbPlanDirPath))
{
    System.IO.Directory.CreateDirectory(WbPlanDirPath);
}  
Alvin Wong
  • 12,210
  • 5
  • 51
  • 77
1

It should be created on the root level for the volume for the current directory. Check Environment.CurrentDirectory.

Torbjörn Hansson
  • 18,354
  • 5
  • 33
  • 42
0

That's making a directory in \SavedWebPlans off the root of the volume with the current working directory.

Jeff Foster
  • 43,770
  • 11
  • 86
  • 103
0

It's in the same parent directory (the directory containing your program) as your program.

Instead of "\\SavedWbPlans";

Use "SavedWbPlans";

That will save it in the current directory (the same directory as your program)

Chibueze Opata
  • 9,856
  • 7
  • 42
  • 65
0

CreateDirectory returns a DirectoryInfo object that points to the created directory.

Check its properties to find out where it was created.

Jens H
  • 4,590
  • 2
  • 25
  • 35