我使用 libNunrar
站点来提取.rar
文件:
RarArchive.WriteToDirectory(fs.Name, Path.Combine(@"D:\DataDownloadCenter", path2), ExtractOptions.Overwrite);
解压工作正常,但我无法在提取操作后删除原始压缩文件
System.IO.File.Delete(path);
因为该文件被另一个进程使用, 所以孔函数:
try
{
FileStream fs = File.OpenRead(path);
if(path.Contains(".rar")){
try
{
RarArchive.WriteToDirectory(fs.Name, Path.Combine(@"D:\DataDownloadCenter", path2), ExtractOptions.Overwrite);
fs.Close();
}
catch { }
}
catch { return; }
finally
{
if (zf != null)
{
zf.IsStreamOwner = true; // Makes close also shut the underlying stream
zf.Close(); // Ensure we release resources
}
}
try
{
System.IO.File.Delete(path);
}
catch { }
那么我可以在解压后删除压缩文件吗?