I have numerous large files that I have to transfer. My TX program keeps hanging when I zip everything into one large file. So I want to zip the individual files.
namespace WindowsFormsApplication1
{
public partial class UncompressFolder : Form
{
public UncompressFolder()
{
InitializeComponent();
}
void ProcessFiles(string path, string choice="U")
{
string[] files;
files = Directory.GetFiles(path);
foreach (string file in files)
{
// Process each file
if (!file.ToUpper().Contains("zip"))
{
FileInfo fi = new FileInfo(file);
string startPath = fi.DirectoryName;
string zipPath = fi.DirectoryName + @"\zipped\";
string zipFile = zipPath + fi.Name+".zip";
string extractPath = startPath + @"\unzipped";
if (!Directory.Exists(extractPath))
{
Directory.CreateDirectory(extractPath);
}
if (choice == "Z")
{
// zip it --> always give me the "File's In Use Error"
// option I had tried but did not work --> Directory.CreateDirectory(zipPath);
System.IO.Compression.ZipFile.CreateFromDirectory(startPath, zipFile);
}
else
{// unzip -- works fine
System.IO.Compression.ZipFile.ExtractToDirectory(file, extractPath);
}
}
}
}
private void button1_Click(object sender, EventArgs e)
{
this.folderBrowserDialog1.ShowDialog();
ProcessFiles(folderBrowserDialog1.SelectedPath, "U");
}
private void button2_Click(object sender, EventArgs e)
{
this.folderBrowserDialog1.ShowDialog();
ProcessFiles(folderBrowserDialog1.SelectedPath,"Z");
}
}
}
I saw the posts about people zipping into their existing files and I don't think that's what I'm doing. I would be so happy and appreciative if someone could help me figure this out.