delete files after zipping

Dec 11, 2012 at 5:53 PM
Edited Dec 11, 2012 at 6:12 PM

Hi, i've developed my own application to compress a large number of files from a directory, but the problem is that i need to delete the original files AFTER the filling into my new zip file.

I wrote a method to compress all files and then to looping all the files into my directories and try to delete them, but... it's not possible because the files are busy from another process...

I'm getting crazy, could someone help me?

In this application it's not possible to close the application to delete the files, i need to delete them during the application running.

using (ZipFile myZip = new ZipFile())
            {
                try
                {
                    myZip.AddFiles(files);
                    totalFilesProcessed = files.Length;

                    myZip.Save(_dirBackup + "\\" + _fileBackupName + ".zip");
                }
                catch (Exception exc) { Console.WriteLine(exc.Message); }
                finally
                { 
                    myZip.Dispose();
                    // deleteFiles();
                }
            }

 

in my deleteFiles() method i receve an exception that the files are in use by another process....

Thanks for any ideas.

Emanuele

Dec 12, 2012 at 10:56 AM

Hello,

 

Try to run the delete command after the using clause:

using(...)
{
...
}
DeleteAllFiles();

 

Best regards,

Silviu.