Language

TarFile.ExtractToDirectory Method

Definition

Overloads

Name Description
ExtractToDirectory(Stream, String, Boolean)

Extracts the contents of a stream that represents a tar archive into the specified directory.

ExtractToDirectory(Stream, String, TarExtractOptions)
ExtractToDirectory(String, String, Boolean)

Extracts the contents of a tar file into the specified directory.

ExtractToDirectory(String, String, TarExtractOptions)

ExtractToDirectory(Stream, String, Boolean)

Source:
TarFile.cs
Source:
TarFile.cs
Source:
TarFile.cs
Source:
TarFile.cs
Source:
TarFile.cs

Extracts the contents of a stream that represents a tar archive into the specified directory.

public:
 static void ExtractToDirectory(System::IO::Stream ^ source, System::String ^ destinationDirectoryName, bool overwriteFiles);
public static void ExtractToDirectory(System.IO.Stream source, string destinationDirectoryName, bool overwriteFiles);
static member ExtractToDirectory : System.IO.Stream * string * bool -> unit
Public Shared Sub ExtractToDirectory (source As Stream, destinationDirectoryName As String, overwriteFiles As Boolean)

Parameters

source
Stream

The stream containing the tar archive.

destinationDirectoryName
String

The path of the destination directory where the filesystem entries should be extracted. In .NET 11 and earlier versions, the directory must already exist. In .NET 12 and later versions, missing destination and parent directories are created as needed when entries are extracted. An empty archive does not create any directories.

overwriteFiles
Boolean

true to overwrite files and directories in destinationDirectoryName; false to avoid overwriting, and throw if any files or directories are found with existing names.

Exceptions

source or destinationDirectoryName is null.

.NET 11 and earlier versions: The destinationDirectoryName directory does not exist.

Permissions are insufficient.

Extracting one of the tar entries would have resulted in a file outside the specified destination directory.

-or-

destinationDirectoryName is empty.

-or-

source does not support reading.

.NET 11 and later versions only: An entry's checksum is invalid.

An I/O exception occurred.

Remarks

Warning

This method must not be used to extract untrusted archives. It doesn't enforce any size limits, entry count limits, or other policies needed for safe extraction of untrusted archives. For more information on safely extracting archives from untrusted sources, see Best practices for using zip and tar archives.

In .NET 11 and earlier versions, the directory specified by destinationDirectoryName must already exist. If it doesn't exist, this method throws an DirectoryNotFoundException, even if the archive is empty.

In .NET 12 and later versions, the destination directory can already exist. Missing destination and parent directories are created as needed when entries are extracted. An empty archive doesn't create any directories.

If a symbolic link or junction in the tar archive results in a file being extracted outside the specified destinationDirectoryName, an IOException is thrown to ensure extraction remains within the same directory.

If destinationDirectoryName or any of its parent directories is a pre-existing junction or symbolic link, the link is followed and the extraction writes to the final target folder.

Files of type BlockDevice, CharacterDevice, or Fifo can only be extracted in Unix platforms.

Elevation is required to extract a BlockDevice or CharacterDevice to disk.

Applies to

ExtractToDirectory(Stream, String, TarExtractOptions)

Source:
TarFile.cs
public:
 static void ExtractToDirectory(System::IO::Stream ^ source, System::String ^ destinationDirectoryName, System::Formats::Tar::TarExtractOptions ^ options);
public static void ExtractToDirectory(System.IO.Stream source, string destinationDirectoryName, System.Formats.Tar.TarExtractOptions options);
static member ExtractToDirectory : System.IO.Stream * string * System.Formats.Tar.TarExtractOptions -> unit
Public Shared Sub ExtractToDirectory (source As Stream, destinationDirectoryName As String, options As TarExtractOptions)

Parameters

source
Stream
destinationDirectoryName
String

The path to the directory in which to place the extracted files. In .NET 11 and earlier versions, the directory must already exist. In .NET 12 and later versions, missing destination and parent directories are created as needed when entries are extracted. An empty archive does not create any directories.

Exceptions

.NET 11 and earlier versions: The destinationDirectoryName directory does not exist.

Remarks

Warning

This method must not be used to extract untrusted archives. It doesn't enforce any size limits, entry count limits, or other policies needed for safe extraction of untrusted archives. For more information on safely extracting archives from untrusted sources, see Best practices for using zip and tar archives.

In .NET 11 and earlier versions, the directory specified by destinationDirectoryName must already exist. If it doesn't exist, this method throws an DirectoryNotFoundException, even if the archive is empty.

In .NET 12 and later versions, the destination directory can already exist. Missing destination and parent directories are created as needed when entries are extracted. An empty archive doesn't create any directories.

The path can be relative or absolute. A relative path is interpreted as relative to the current working directory.

If an error occurs during extraction, the archive remains partially extracted.

Set OverwriteFiles to true to overwrite existing files. The default is false. Use HardLinkMode to control how hard link entries are extracted.

If a symbolic link or junction in the tar archive results in a file being extracted outside the specified destinationDirectoryName, an IOException is thrown to ensure extraction remains within the same directory.

If destinationDirectoryName or any of its parent directories is a pre-existing junction or symbolic link, the link is followed and the extraction writes to the final target folder.

Files of type BlockDevice, CharacterDevice, or Fifo can only be extracted in Unix platforms.

Elevation is required to extract a BlockDevice or CharacterDevice to disk.

The source stream is left open after extraction.

Applies to

ExtractToDirectory(String, String, Boolean)

Source:
TarFile.cs
Source:
TarFile.cs
Source:
TarFile.cs
Source:
TarFile.cs
Source:
TarFile.cs

Extracts the contents of a tar file into the specified directory.

public:
 static void ExtractToDirectory(System::String ^ sourceFileName, System::String ^ destinationDirectoryName, bool overwriteFiles);
public static void ExtractToDirectory(string sourceFileName, string destinationDirectoryName, bool overwriteFiles);
static member ExtractToDirectory : string * string * bool -> unit
Public Shared Sub ExtractToDirectory (sourceFileName As String, destinationDirectoryName As String, overwriteFiles As Boolean)

Parameters

sourceFileName
String

The path of the tar file to extract.

destinationDirectoryName
String

The path of the destination directory where the filesystem entries should be extracted. In .NET 11 and earlier versions, the directory must already exist. In .NET 12 and later versions, missing destination and parent directories are created as needed when entries are extracted. An empty archive does not create any directories.

overwriteFiles
Boolean

true to overwrite files and directories in destinationDirectoryName; false to avoid overwriting, and throw if any files or directories are found with existing names.

Exceptions

sourceFileName or destinationDirectoryName is null.

.NET 11 and earlier versions: The destinationDirectoryName directory does not exist.

The sourceFileName file path is not found.

Permissions are insufficient.

Extracting one of the tar entries would have resulted in a file outside the specified destination directory.

-or-

sourceFileName or destinationDirectoryName is empty.

.NET 11 and later versions only: An entry's checksum is invalid.

An I/O exception occurred.

Remarks

Warning

This method must not be used to extract untrusted archives. It doesn't enforce any size limits, entry count limits, or other policies needed for safe extraction of untrusted archives. For more information on safely extracting archives from untrusted sources, see Best practices for using zip and tar archives.

In .NET 11 and earlier versions, the directory specified by destinationDirectoryName must already exist. If it doesn't exist, this method throws an DirectoryNotFoundException, even if the archive is empty.

In .NET 12 and later versions, the destination directory can already exist. Missing destination and parent directories are created as needed when entries are extracted. An empty archive doesn't create any directories.

If a symbolic link or junction in the tar archive results in a file being extracted outside the specified destinationDirectoryName, an IOException is thrown to ensure extraction remains within the same directory.

If destinationDirectoryName or any of its parent directories is a pre-existing junction or symbolic link, the link is followed and the extraction writes to the final target folder.

Files of type BlockDevice, CharacterDevice, or Fifo can only be extracted in Unix platforms.

Elevation is required to extract a BlockDevice or CharacterDevice to disk.

Applies to

ExtractToDirectory(String, String, TarExtractOptions)

Source:
TarFile.cs
public:
 static void ExtractToDirectory(System::String ^ sourceFileName, System::String ^ destinationDirectoryName, System::Formats::Tar::TarExtractOptions ^ options);
public static void ExtractToDirectory(string sourceFileName, string destinationDirectoryName, System.Formats.Tar.TarExtractOptions options);
static member ExtractToDirectory : string * string * System.Formats.Tar.TarExtractOptions -> unit
Public Shared Sub ExtractToDirectory (sourceFileName As String, destinationDirectoryName As String, options As TarExtractOptions)

Parameters

sourceFileName
String
destinationDirectoryName
String

The path to the directory in which to place the extracted files. In .NET 11 and earlier versions, the directory must already exist. In .NET 12 and later versions, missing destination and parent directories are created as needed when entries are extracted. An empty archive does not create any directories.

Exceptions

.NET 11 and earlier versions: The destinationDirectoryName directory does not exist.

Remarks

Warning

This method must not be used to extract untrusted archives. It doesn't enforce any size limits, entry count limits, or other policies needed for safe extraction of untrusted archives. For more information on safely extracting archives from untrusted sources, see Best practices for using zip and tar archives.

In .NET 11 and earlier versions, the directory specified by destinationDirectoryName must already exist. If it doesn't exist, this method throws an DirectoryNotFoundException, even if the archive is empty.

In .NET 12 and later versions, the destination directory can already exist. Missing destination and parent directories are created as needed when entries are extracted. An empty archive doesn't create any directories.

The path can be relative or absolute. A relative path is interpreted as relative to the current working directory.

If an error occurs during extraction, the archive remains partially extracted.

Set OverwriteFiles to true to overwrite existing files. The default is false. Use HardLinkMode to control how hard link entries are extracted.

If a symbolic link or junction in the tar archive results in a file being extracted outside the specified destinationDirectoryName, an IOException is thrown to ensure extraction remains within the same directory.

If destinationDirectoryName or any of its parent directories is a pre-existing junction or symbolic link, the link is followed and the extraction writes to the final target folder.

Files of type BlockDevice, CharacterDevice, or Fifo can only be extracted in Unix platforms.

Elevation is required to extract a BlockDevice or CharacterDevice to disk.

Applies to