|
C # file and com tutorial |
|
|
|
Contributed by Joe
|
|
Thursday, 06 July 2006 |
|
Page 1 of 2 How to determine If a Path Is a Directory or a File in c#The System.IO.Directory and System.IO.File classes both provide an Exists method. The Directory.Exists method returns true if a supplied relative or absolute path corresponds to an existing directory, even a shared folder with an UNC name. File.Exists returns true if the path corresponds to an existing file.
using System; using System.IO; namespace biz.hotdir { static class FileDemo { static void Main(string[] args) { foreach (string arg in args) { Console.Write(arg); if (Directory.Exists(arg)) { Console.WriteLine(" is a directory"); } else if (File.Exists(arg)) { Console.WriteLine(" is a file"); } else { Console.WriteLine(" does not exist"); } } // Wait to continue. Console.WriteLine(Environment.NewLine); Console.WriteLine("Main method complete. Press Enter."); Console.ReadLine(); } } } Access a COM Port in C#
<< Start < Previous 1 2 Next > End >> |
|
Last Updated ( Thursday, 06 July 2006 )
|