Export (0) Print
Expand All

FileSystem Class

Provides properties and methods for working with drives, files, and directories.

System::Object
  Microsoft.VisualBasic.FileIO::FileSystem

Namespace:  Microsoft.VisualBasic.FileIO
Assembly:  Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)

[HostProtectionAttribute(SecurityAction::LinkDemand, Resources = HostProtectionResource::ExternalProcessMgmt)]
public ref class FileSystem

The FileSystem type exposes the following members.

  NameDescription
Public methodFileSystemInitializes a new instance of the FileSystem class.
Top

  NameDescription
Public propertyStatic memberCurrentDirectoryGets or sets the current directory.
Public propertyStatic memberDrivesReturns a read-only collection of all available drive names.
Top

  NameDescription
Public methodStatic memberCombinePathCombines two paths and returns a properly formatted path.
Public methodStatic memberCopyDirectory(String, String)Copies the contents of a directory to another directory.
Public methodStatic memberCopyDirectory(String, String, UIOption)Copies the contents of a directory to another directory.
Public methodStatic memberCopyDirectory(String, String, Boolean)Copies the contents of a directory to another directory.
Public methodStatic memberCopyDirectory(String, String, UIOption, UICancelOption)Copies the contents of a directory to another directory.
Public methodStatic memberCopyFile(String, String)Copies a file to a new location.
Public methodStatic memberCopyFile(String, String, UIOption)Copies a file to a new location.
Public methodStatic memberCopyFile(String, String, Boolean)Copies a file to a new location.
Public methodStatic memberCopyFile(String, String, UIOption, UICancelOption)Copies a file to a new location.
Public methodStatic memberCreateDirectoryCreates a directory.
Public methodStatic memberDeleteDirectory(String, DeleteDirectoryOption)Deletes a directory.
Public methodStatic memberDeleteDirectory(String, UIOption, RecycleOption)Deletes a directory.
Public methodStatic memberDeleteDirectory(String, UIOption, RecycleOption, UICancelOption)Deletes a directory.
Public methodStatic memberDeleteFile(String)Deletes a file.
Public methodStatic memberDeleteFile(String, UIOption, RecycleOption)Deletes a file.
Public methodStatic memberDeleteFile(String, UIOption, RecycleOption, UICancelOption)Deletes a file.
Public methodStatic memberDirectoryExistsReturns True if the specified directory exists.
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Public methodStatic memberFileExistsReturns True if the specified file exists.
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodStatic memberFindInFiles(String, String, Boolean, SearchOption)Returns a read-only collection of strings representing the names of files containing the specified text.
Public methodStatic memberFindInFiles(String, String, Boolean, SearchOption, array<String>)Returns a read-only collection of strings representing the names of files containing the specified text.
Public methodStatic memberGetDirectories(String)Returns a collection of strings representing the path names of subdirectories within a directory.
Public methodStatic memberGetDirectories(String, SearchOption, array<String>)Returns a collection of strings representing the path names of subdirectories within a directory.
Public methodStatic memberGetDirectoryInfoReturns a DirectoryInfo object for the specified path.
Public methodStatic memberGetDriveInfoReturns a DriveInfo object for the specified drive.
Public methodStatic memberGetFileInfoReturns a FileInfo object for the specified file.
Public methodStatic memberGetFiles(String)Returns a read-only collection of strings representing the names of files within a directory.
Public methodStatic memberGetFiles(String, SearchOption, array<String>)Returns a read-only collection of strings representing the names of files within a directory.
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodStatic memberGetNameParses the file name out of the path provided.
Public methodStatic memberGetParentPathReturns the parent path of the provided path.
Public methodStatic memberGetTempFileNameCreates a uniquely named zero-byte temporary file on disk and returns the full path of that file.
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodStatic memberMoveDirectory(String, String)Moves a directory from one location to another.
Public methodStatic memberMoveDirectory(String, String, UIOption)Moves a directory from one location to another.
Public methodStatic memberMoveDirectory(String, String, Boolean)Moves a directory from one location to another.
Public methodStatic memberMoveDirectory(String, String, UIOption, UICancelOption)Moves a directory from one location to another.
Public methodStatic memberMoveFile(String, String)Moves a file to a new location.
Public methodStatic memberMoveFile(String, String, UIOption)Moves a file to a new location.
Public methodStatic memberMoveFile(String, String, Boolean)Moves a file to a new location.
Public methodStatic memberMoveFile(String, String, UIOption, UICancelOption)Moves a file to a new location.
Public methodStatic memberOpenTextFieldParser(String)The OpenTextFieldParser method allows you to create a TextFieldParser object, which provides a way to easily and efficiently parse structured text files, such as logs. The TextFieldParser object can be used to read both delimited and fixed-width files.
Public methodStatic memberOpenTextFieldParser(String, array<Int32>)The OpenTextFieldParser method allows you to create a TextFieldParser object, which provides a way to easily and efficiently parse structured text files, such as logs. The TextFieldParser object can be used to read both delimited and fixed-width files.
Public methodStatic memberOpenTextFieldParser(String, array<String>)The OpenTextFieldParser method allows you to create a TextFieldParser object, which provides a way to easily and efficiently parse structured text files, such as logs. The TextFieldParser object can be used to read both delimited and fixed-width files.
Public methodStatic memberOpenTextFileReader(String)Opens a StreamReader object to read from a file.
Public methodStatic memberOpenTextFileReader(String, Encoding)Opens a StreamReader object to read from a file.
Public methodStatic memberOpenTextFileWriter(String, Boolean)Opens a StreamWriter object to write to the specified file.
Public methodStatic memberOpenTextFileWriter(String, Boolean, Encoding)Opens a StreamWriter to write to the specified file.
Public methodStatic memberReadAllBytesReturns the contents of a file as a byte array.
Public methodStatic memberReadAllText(String)Returns the contents of a text file as a String.
Public methodStatic memberReadAllText(String, Encoding)Returns the contents of a text file as a String.
Public methodStatic memberRenameDirectoryRenames a directory.
Public methodStatic memberRenameFileRenames a file.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Public methodStatic memberWriteAllBytesWrites data to a binary file.
Public methodStatic memberWriteAllText(String, String, Boolean)Writes text to a file.
Public methodStatic memberWriteAllText(String, String, Boolean, Encoding)Writes text to a file.
Top

The following table lists examples of tasks involving the My.Computer.FileSystem object.

To

See

Read from a text file

How to: Read From Text Files in Visual Basic

Read from a delimited text file

How to: Read From Comma-Delimited Text Files in Visual Basic

Read from a fixed-width text file

How to: Read From Fixed-width Text Files in Visual Basic

Read from a text file with multiple formats

How to: Read From Text Files with Multiple Formats in Visual Basic

Read from a binary file

How to: Read From Binary Files in Visual Basic

Read from text files in the MyDocuments directory

How to: Read From Existing Text Files in My Documents (Visual Basic)

Read from a text file with a StreamReader

How to: Read Text from Files with a StreamReader (Visual Basic)

Write to a text file

How to: Write Text to Files in Visual Basic

Append to a text file

How to: Append to Text Files in Visual Basic

Write to a binary file

How to: Write to Binary Files in Visual Basic

Write to text files in the MyDocuments directory

How to: Write Text to Files in the My Documents Directory in Visual Basic

Write to a text file with a StreamWriter

How to: Write Text to Files with a StreamWriter in Visual Basic

Copy files with a specific pattern

How to: Copy Files with a Specific Pattern to a Directory in Visual Basic

Copy a file to the same directory

How to: Create a Copy of a File in the Same Directory in Visual Basic

Copy a file to a different directory

How to: Create a Copy of a File in a Different Directory in Visual Basic

Create a file

How to: Create a File in Visual Basic

Delete a file

How to: Delete a File in Visual Basic

Delete all the files in a directory

How to: Delete All Files in a Directory in Visual Basic

Find files with a specific pattern

How to: Find Files with a Specific Pattern in Visual Basic

Move a file

How to: Move a File in Visual Basic

Move a collection of files

How to: Move a Collection of Files in Visual Basic

Rename a file

How to: Rename a File in Visual Basic

Rename a directory

How to: Rename a Directory in Visual Basic

Copy a directory to another directory

How to: Copy a Directory to Another Directory in Visual Basic

Create a directory

How to: Create a Directory in Visual Basic

Delete a directory

How to: Delete a Directory in Visual Basic

Find subdirectories with a specific pattern

How to: Find Subdirectories with a Specific Pattern in Visual Basic

Get the collection of files in a directory

How to: Get the Collection of Files in a Directory in Visual Basic

Determine how many files are in a directory

How to: Determine How Many Files Are in a Directory in Visual Basic

Move a directory

How to: Move a Directory in Visual Basic

Move the contents of a directory

How to: Move the Contents of a Directory in Visual Basic

Read from the MyDocuments directory

How to: Retrieve the Contents of the My Documents Directory in Visual Basic

Parse a file path

How to: Parse File Paths in Visual Basic

NoteNote

The HostProtectionAttribute attribute applied to this type or member has the following Resources property value: Resources. The HostProtectionAttribute does not affect desktop applications (which are typically started by double-clicking an icon, typing a command, or entering a URL in a browser). For more information, see the HostProtectionAttribute class or SQL Server Programming and Host Protection Attributes.

This example checks to determine whether the folder C:\backup\logs exists and checks its properties.


Dim logInfo As System.IO.DirectoryInfo
If My.Computer.FileSystem.DirectoryExists("C:\backup\logs") Then
    logInfo = My.Computer.FileSystem.GetDirectoryInfo(
      "C:\backup\logs")
End If


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

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

Community Additions

ADD
Show:
© 2014 Microsoft