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 ?

2
  • 1
    Just try to print path of directory you are created. Commented Jun 20, 2013 at 9:50
  • You could also print the directory maybe via console/messagebox with (new DirectoryInfo(WbPlanDirPath)).FullName Commented Jun 20, 2013 at 9:52

5 Answers 5

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);
}  
Sign up to request clarification or add additional context in comments.

1 Comment

Nice and clear explanation!
1

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

Comments

0

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

Comments

0

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

Check its properties to find out where it was created.

Comments

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)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.