मान लें कि हमें निम्न फ़ाइल ढूंढनी है -
E:\new.txt
उपरोक्त फ़ाइल के अस्तित्व की जाँच करने के लिए, मौजूद () विधि का उपयोग करें -
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!