This documentation is archived and is not being maintained.

FileSystemInfo Class

Provides the base class for both FileInfo and DirectoryInfo objects.

For a list of all members of this type, see FileSystemInfo Members.


[Visual Basic]
MustInherit Public Class FileSystemInfo
   Inherits MarshalByRefObject
   Implements ISerializable
public abstract class FileSystemInfo : MarshalByRefObject,
public __gc __abstract class FileSystemInfo : public
   MarshalByRefObject, ISerializable
abstract class FileSystemInfo extends MarshalByRefObject
   implements ISerializable

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.


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.

The following table lists examples of other typical or related I/O tasks.

To do this... See the example in this topic...
Create a text file. Writing Text to a File
Write to a text file. Writing Text to a File
Read from a text file. Reading Text from a File
Append text to a file. Opening and Appending to a Log File



Delete a file. File.Delete


Rename or move a file. File.Move


Copy a file. File.Copy


Create a directory. Directory.CreateDirectory


Create a subdirectory. CreateSubdirectory
Rename or move a directory. Directory.Move


Delete a directory. Directory.Delete


Copy a directory. Directory
Sort files in a directory by size. GetFileSystemInfos
See the files in a directory. Name
See the subdirectories of a directory. GetDirectories


See all the files in all subdirectories of a directory. GetFileSystemInfos
Find the size of a directory. Directory
Get the size of a file. FileInfo.Length
Get the attributes of a file. File.GetAttributes
Set the attributes of a file. File.SetAttributes
Determine if a file exists. File.Exists
Read from a binary file. Reading and Writing to a Newly Created Data File
Write to a binary file. Reading and Writing to a Newly Created Data File
Retrieve a file extension. Path.GetExtension
Retrieve the fully qualified path of a file. Path.GetFullPath
Retrieve the file name and extension from a path. Path.GetFileName
Change the extension of a file. Path.ChangeExtension


Namespace: System.IO

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

Assembly: Mscorlib (in Mscorlib.dll)

See Also

FileSystemInfo Members | System.IO Namespace | Working with I/O | Reading Text from a File | Writing Text to a File | Basic File I/O | Reading and Writing to a Newly Created Data File