Solved

c# File System method - FolderExists()

Posted on 2008-06-26
3
808 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Calculate number of nights between two dates 5 93
asp web application 3 43
c# DateTime Format validation 4 69
How to escape alias names for Oracle query 1 25
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
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…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

726 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