আমাদের যে ফাইলটি খুঁজতে হবে তা ধরা যাক:
E:\new.txt
উপরের ফাইলের অস্তিত্ব যাচাই করতে Exists() মেথড ব্যবহার করুন:
if (File.Exists(@"E:\new.txt"))
{
Console.WriteLine("File exists...");
}
সম্পূর্ণ উদাহরণ
using System;
using System.IO;
public class Demo
{
public static void Main()
{
if (File.Exists(@"E:\new.txt"))
{
Console.WriteLine("File exists...");
}
else
{
Console.WriteLine("File does not exist in the E directory!");
}
}
}
আউটপুট
File does not exist in the E directory!