Solved

c# File System method - FolderExists()

Posted on 2008-06-26
3
805 Views
Last Modified: 2008-06-26
Greetings:

I'm hoping to get code and supporting namespace that will execute the following routine:

FolderExists()

For example:

using ??

void CheckFolder()
{
...                      // necessary variables like 'string FolderPath'
FolderExists()       // correct call
return;
}

Thanks
0
Comment
Question by:John500
3 Comments
 
LVL 16

Accepted Solution

by:
burakiewicz earned 500 total points
ID: 21876479
using System.IO;

Directory.Exists(strPath);
0
 
LVL 6

Expert Comment

by:Bruce_1975
ID: 21876490
The function you are searchin for is included in the System.IO.Directory - class:
System.IO.Directory.Exists("MyFolder")

Regards,
Bruce
0
 
LVL 18

Expert Comment

by:jcoehoorn
ID: 21876902
I see you're asking a lot of file and directory questions all at once, meaning you're probably going to need a bunch of information about a file or directory at the same point in your program.

With that in mind, there are two main ways to get all of this information in .Net:  
1) System.IO.File/System.IO.Directory
2) System.IO.FileInfo/System.IO.DirectoryInfo

As people show you how to do things, as you get various answers from people you should probably favor the FileInfo/DirectoryInfo method to avoid needing to make repeated calls out to the file system.

For example, in this case you could also do it like this, and if you need other information about the directory at the same time it's probably the better choice:
System.IO.DirectoryInfo di = new System.IO.DirectoryInfo("MyFolder");
di.Exists();

Open in new window

0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question