FileSystemInfo Class
Assembly: mscorlib (in mscorlib.dll)
'Declaration <SerializableAttribute> _ <ComVisibleAttribute(True)> _ Public MustInherit Class FileSystemInfo Inherits MarshalByRefObject Implements ISerializable 'Usage Dim instance As FileSystemInfo
/** @attribute SerializableAttribute() */ /** @attribute ComVisibleAttribute(true) */ public abstract class FileSystemInfo extends MarshalByRefObject implements ISerializable
SerializableAttribute ComVisibleAttribute(true) public abstract class FileSystemInfo extends MarshalByRefObject implements ISerializable
Not applicable.
The FileSystemInfo class contains methods that are common to file and directory manipulation. A FileSystemInfo object can represent either a file or a directory, thus serving as the basis for FileInfo or DirectoryInfo objects. Use this base class when parsing a lot of files and directories.
When first called, FileSystemInfo calls Refresh and returns the cached information on APIs to get attributes and so on. On subsequent calls, you must call Refresh to get the latest copy of the information.
A derived class can inherit from FileSystemInfo only if the derived class has the AllAccess permission from the FileIOPermissionAccess enumeration.
In members that accept a path, the path can refer to a file or just a directory. The specified path can also refer to a relative path or a Universal Naming Convention (UNC) path for a server and share name. For example, all the following are acceptable paths:
-
"c:\\MyDir\\MyFile.txt" in C#, or "c:\MyDir\MyFile.txt" in Visual Basic.
-
"c:\\MyDir" in C#, or "c:\MyDir" in Visual Basic.
-
"MyDir\\MySubdir" in C#, or "MyDir\MySubDir" in Visual Basic.
-
"\\\\MyServer\\MyShare" in C#, or "\\MyServer\MyShare" in Visual Basic.
For a list of common I/O tasks, see Common I/O Tasks.
The following example shows how to loop through all the files and directories, querying some information about each entry.
Imports System.IO Module Module1 Sub Main() ' Loop through all the immediate subdirectories of C. For Each entry As String In Directory.GetDirectories("C:\") DisplayFileSystemInfoAttributes(New DirectoryInfo(entry)) Next ' Loop through all the files in C. For Each entry As String In Directory.GetFiles("C:\") DisplayFileSystemInfoAttributes(New FileInfo(entry)) Next End Sub Sub DisplayFileSystemInfoAttributes(ByVal fsi As IO.FileSystemInfo) ' Assume that this entry is a file. Dim entryType As String = "File" ' Determine if this entry is really a directory. If (fsi.Attributes And FileAttributes.Directory) <> 0 Then entryType = "Directory" End If ' Show this entry's type, name, and creation date. Console.WriteLine("{0} entry {1} was created on {2:D}", _ entryType, fsi.FullName, fsi.CreationTime) End Sub End Module ' Output will vary based on contents of drive C. ' ' Directory entry C:\Documents and Settings was created on Tuesday, November 25, 2003 ' Directory entry C:\Inetpub was created on Monday, January 12, 2004 ' Directory entry C:\Program Files was created on Tuesday, November 25, 2003 ' Directory entry C:\RECYCLER was created on Tuesday, November 25, 2003 ' Directory entry C:\System Volume Information was created on Tuesday, November 2, 2003 ' Directory entry C:\WINDOWS was created on Tuesday, November 25, 2003 ' File entry C:\IO.SYS was created on Tuesday, November 25, 2003 ' File entry C:\MSDOS.SYS was created on Tuesday, November 25, 2003 ' File entry C:\pagefile.sys was created on Saturday, December 27, 2003
- FileIOPermission for permission to inherit from this class. Associated enumeration: Unrestricted Security Action: Inheritance Demand
System.MarshalByRefObject
System.IO.FileSystemInfo
System.IO.DirectoryInfo
System.IO.FileInfo
Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.