By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,169 Members | 1,417 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,169 IT Pros & Developers. It's quick & easy.

very very simple question

P: n/a
hi,

i was wondering if u can help with the following

how can i figure out that a given path, represents a file or folder

Feb 5 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On 5 Feb, 12:08, "xxxx" <xxxxl...@gmail.comwrote:
hi,

i was wondering if u can help with the following

how can i figure out that a given path, represents a file or folder
Console.WriteLine(System.IO.File.Exists(@"C:
\AUTOEXEC.BAT").ToString()); //true
Console.WriteLine(System.IO.Directory.Exists(@"C:
\WINDOWS").ToString()); //true
Console.WriteLine(System.IO.Directory.Exists(@"C:
\AUTOEXEC.BAT").ToString()); //false
Console.WriteLine(System.IO.File.Exists(@"C:\WINDO WS").ToString()); //
false

So check if the file exists, and if not, check if the directory exists
(Important to add that step, don't just assume as the path may be
invalid).

Incidently, Console.WriteLine(System.IO.Directory.Exists(@"C:\ WINDOWS
\").ToString());
will work as well, so no need to worry about trailing \ characters.

Feb 5 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.