c# - Ignore file if it is corrupted -


i using ionic zip in wcf service unzip files uploaded 'client'.the files zipped using ionic zip.however,there have been instances zipped files 'corrupted'.since code scans entire folder zipped files,exceptions thrown picking same 'corrupted' zipped files everytime.this stopped other files being processed.here's code:

foreach (string filepath in directory.getfiles(zippedfilesdestinationfolder)) {     using (zipfile zip1 = zipfile.read(filepath))             {                 foreach (zipentry e in zip1)                 {                     e.extract(unpackdirectory, extractexistingfileaction.overwritesilently);                 }             } } 

i want move corrupted file folder , continue extracting other zipped files in folder.how should code modified achieve this?

it stopped other files because exception unhandled within loop, causing loop exit. adding try/catch around read of zipped files allow files fail still allow next file processed.

foreach (string filepath in directory.getfiles(zippedfilesdestinationfolder)) {     try     {         using (zipfile zip1 = zipfile.read(filepath))         {             foreach (zipentry e in zip1)             {                 e.extract(unpackdirectory, extractexistingfileaction.overwritesilently);             }         }     }     catch(exception ex)      {          /* log ex here */          /* move corrupt file */     } } 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -