Determine If a Path Is a Directory or a File - CSharp File IO

CSharp examples for File IO:Path

Description

Determine If a Path Is a Directory or a File

Demo Code


using System;// ww  w .  ja  v  a2s. c o  m
using System.IO;

    static class MainClass
    {
        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");
                }
            }
        }
    }

Related Tutorials