RarFile Class
Opens and extracts the RAR archives of the file system, finding the volumes of a multi-volume archive next to the first one.
public static class RarFileMethods
| Name | Description |
|---|---|
| ExtractToDirectory(string, string, bool, ArchiveReaderOptions?) | Extracts the entries of a RAR archive to a directory. An entry whose path leaves the directory (.., a rooted path, or a symbolic link that points outside of it) is rejected with an IOException. |
| ExtractToDirectoryAsync(string, string, bool, ArchiveReaderOptions?, CancellationToken) | Extracts the entries of a RAR archive to a directory. An entry whose path leaves the directory (.., a rooted path, or a symbolic link that points outside of it) is rejected with an IOException. |
| OpenRead(string, ArchiveReaderOptions?) | Opens a RAR archive. When ArchiveReaderOptions.VolumeResolver is null, the volumes of a multi-volume archive are found next to it: name.part2.rar, name.part3.rar, ... (keeping the number of digits of the first volume, as in name.part01.rar), or name.r00, name.r01, ... for the volumes of the old naming scheme that follow name.rar. |
ExtractToDirectory(string, string, bool, ArchiveReaderOptions?)
RarFile.csExtracts the entries of a RAR archive to a directory. An entry whose path leaves the directory (.., a rooted path, or a symbolic link that points outside of it) is rejected with an IOException.
public static void ExtractToDirectory(string sourceArchiveFileName, string destinationDirectoryName, bool overwriteFiles = false, ArchiveReaderOptions? options = null)Parameters
sourceArchiveFileNamestring- The path of the archive, the first volume of a multi-volume archive.
destinationDirectoryNamestring- The directory to extract to. It is created when it does not exist.
overwriteFilesbooltrueto replace the existing files;falseto throw anIOExceptionwhen a file exists.optionsArchiveReaderOptions?- The options, or
nullfor the defaults.
Example
RarFile.ExtractToDirectory(archivePath, destination, overwriteFiles: true);
Assert.True(File.Exists(Path.Combine(destination, "sub/dir1/file1.txt")));ExtractToDirectoryAsync(string, string, bool, ArchiveReaderOptions?, CancellationToken)
RarFile.csExtracts the entries of a RAR archive to a directory. An entry whose path leaves the directory (.., a rooted path, or a symbolic link that points outside of it) is rejected with an IOException.
net10.0
public static Task ExtractToDirectoryAsync(string sourceArchiveFileName, string destinationDirectoryName, bool overwriteFiles = false, ArchiveReaderOptions? options = null, CancellationToken cancellationToken = default)net11.0
public static Task ExtractToDirectoryAsync(string sourceArchiveFileName, string destinationDirectoryName, bool overwriteFiles = false, ArchiveReaderOptions? options = null, CancellationToken cancellationToken = default)Parameters
sourceArchiveFileNamestring- The path of the archive, the first volume of a multi-volume archive.
destinationDirectoryNamestring- The directory to extract to. It is created when it does not exist.
overwriteFilesbooltrueto replace the existing files;falseto throw anIOExceptionwhen a file exists.optionsArchiveReaderOptions?- The options, or
nullfor the defaults. cancellationTokenCancellationToken- The token to monitor for cancellation requests.
Returns
Task A task that completes when every entry is extracted.
OpenRead(string, ArchiveReaderOptions?)
RarFile.csOpens a RAR archive. When ArchiveReaderOptions.VolumeResolver is null, the volumes of a multi-volume archive are found next to it: name.part2.rar, name.part3.rar, ... (keeping the number of digits of the first volume, as in name.part01.rar), or name.r00, name.r01, ... for the volumes of the old naming scheme that follow name.rar.
public static RarArchive OpenRead(string path, ArchiveReaderOptions? options = null)Parameters
pathstring- The path of the archive, the first volume of a multi-volume archive.
optionsArchiveReaderOptions?- The options, or
nullfor the defaults.
Returns
RarArchive The archive, which owns the files it opens.
Exceptions
InvalidDataException- The file is not a RAR archive, or the archive is corrupted.
ArchivePasswordException- The headers are encrypted and the password is missing or wrong.