C # file and com tutorial

Home arrow .NET Tutorials arrow C# arrow C # file and com tutorial
C # file and com tutorial Print E-mail
Contributed by Joe   
Thursday, 06 July 2006

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#



Last Updated ( Thursday, 06 July 2006 )

  home              contact us

 

©2006-2009 DeveloperZone.biz   All rights reserved     powered by Mambo Designed by Siteground