FileInfo क्या है
FileInfo किसी file के ID card जैसा है जो आपको उसका नाम, size, और dates बताता है, और आपको इसे copy या delete करने देता है। यह एक specific file describe करता है।
In this page:
Syntax
FileInfo info = new FileInfo(path);
info.Name;
info.Length;
info.Exists;
info.LastWriteTime;
FileInfo
FileInfo एक specific file को represent करता है और Length, Exists, और LastWriteTime जैसी instance properties, साथ ही Delete() और CopyTo() जैसे methods उजागर करता है।
static File class के विपरीत, FileInfo बनने के बाद कुछ जानकारी cache करता है, जो एक ही file पर बार-बार checks के लिए ज़्यादा efficient हो सकता है। यह File के static methods का object-oriented counterpart है।
Note:
FileInfo का उपयोग करें जब आपको एक ही file की कई properties inspect करनी हों — यह बार-बार filesystem calls से बचाता है जो File के static methods हर बार करते हैं।उदाहरण: FileInfo
using System;
using System.IO;
class Program
{
static void Main(string[] args)
{
string path = "info.txt";
File.WriteAllText(path, "some sample content");
FileInfo info = new FileInfo(path);
Console.WriteLine(info.Name);
Console.WriteLine(info.Length);
Console.WriteLine(info.Exists);
}
}
Login to try C/C++/Java/PHP code in the editor
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
आम गलतियां
- किसी ऐसी file के लिए
info.Lengthपढ़ना जो मौजूद नहीं, जो एकFileNotFoundExceptionफेंकता है; पहलेinfo.Existsजांचें। - file बदलने के बाद एक
FileInforeuse करना और stale values पढ़ना, क्योंकि propertiesinfo.Refresh()call करने तक cached रहती हैं। Lengthको characters की संख्या मानना, जबकि यह bytes में file size है।
🔒
Chapter Quiz — Complete all 6 topics to unlock
0/6 topics done
Complete these topics first: