我正在尝试进行编程以进行压缩,.tar
我进行编程的源代码是 Microsoft 主页上提供的示例。但有一个错误。我不知道为什么,一切都和微软主页上的例子一样。
错误是
System.NotSupportedException:不支持给定路径的格式。
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//this directory is what I wanna compress..
string directoryPath = @"C:\\sfdsf";
DirectoryInfo directorySelected = new DirectoryInfo(directoryPath);
foreach (FileInfo filetoCompress in directorySelected.GetFiles())
{
Compress(filetoCompress);
}
}
public static void Compress(FileInfo fileToCompress)
{
using (FileStream originalFileStream = fileToCompress.OpenRead())
{
if ((File.GetAttributes(fileToCompress.FullName) & FileAttributes.Hidden)
!= FileAttributes.Hidden & fileToCompress.Extension != ".tar")
{
using (FileStream compressedFileStream = File.Create(DateTime.Now+ ".tar"))
{
using (DeflateStream compressionStream = new DeflateStream(compressedFileStream, CompressionMode.Compress))
{
originalFileStream.CopyTo(compressionStream);
MessageBox.Show("Compressed" + fileToCompress.Name + "from" + fileToCompress.Length.ToString() + " to" + compressedFileStream.Length.ToString () +" bytes.");
}
}
}
}
}
}
}