这是方法:
private void Compressions(string zipFile,string sources)
{
try
{
string zipFileName = zipFile;
string source = sources;
string output = @"c:\temp";
string programFilesX86 = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFilesX86) + "\\Diagnostic Tool\\7z.dll";
if (File.Exists(programFilesX86))
{
SevenZipExtractor.SetLibraryPath(programFilesX86);
}
else
{
string path = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\7z.dll";
SevenZipExtractor.SetLibraryPath(path);
}
string programFiles = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFiles) + "\\Diagnostic Tool\\7z.dll";
if (File.Exists(programFiles))
{
SevenZipExtractor.SetLibraryPath(programFiles);
}
else
{
if (File.Exists(programFilesX86))
{
SevenZipExtractor.SetLibraryPath(programFilesX86);
}
else
{
string path = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\7z.dll";
SevenZipExtractor.SetLibraryPath(path);
}
}
SevenZipCompressor compressor = new SevenZipCompressor();
compressor.ArchiveFormat = OutArchiveFormat.Zip;
compressor.CompressionMode = CompressionMode.Create;
compressor.TempFolderPath = System.IO.Path.GetTempPath();
string t = Path.Combine(output, zipFileName);
compressor.CompressDirectory(source, t);
this.explorerWindow = Process.Start("explorer", String.Format("/select,{0}", t));
this.TopMost = true;
}
catch (Exception err)
{
Logger.Write("Zip file error: " + err.ToString());
}
}
在底部,变量 t 包含目录和文件名。例如:“c:\temp\test.txt” 我想得到这个文件名的大小。
我该怎么做 ?