C#
System.IO.File.Exists(ファイルパス)
System.IO.FileクラスのExistsメソッドを利用することでファイルが存在するかチェックすることができます。
ファイルが存在していたら true 、存在しなければ false を返します。
アクセス権限がない場合にも例外は発生せず false が返されます。ファイルパスが null、無効なパス、または長さ 0 の文字列である場合も false が返されます。
使用例
string filePath = @"c:\hoge\hoge.txt";
if (System.IO.Directory.Exists(filePath))
{
Console.WriteLine($"{filePath} ファイルあり");
}
else
{
Console.WriteLine($"{filePath} ファイルなし");
}
