SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

FastZip: Using FileFilter to zip a single file (exact match) in .Net 3.5

Last post 12-07-2009 2:56 AM by DavidPierson. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 07-02-2009 11:26 PM

    • dimon
    • Not Ranked
    • Joined on 07-02-2009
    • Posts 4

    FastZip: Using FileFilter to zip a single file (exact match) in .Net 3.5

    So I'm using ICSharpCode.SharpZipLib.Zip.FastZip to compress every single file in folder but the problem is that I have files like "Test.csv", "ReportTest.csv", "EmailTest.csv" etc. All of those files are added to the zip when I run the following:

    FastZip fz = new FastZip();
    fz.CreateZip("Test.zip", "C:\path", false, "Test.csv$");

    If I change last parm to be "^Test.csv$" none of the files is added to the zip so it ends up being empty.

    I even tried using the full path to the file as a 4th parm but zip file was empty as well.

    I also checked the source code and tried the example that is shown in comments: "The following expression includes all name ending in '.dat' with the exception of 'dummy.dat': "+\.dat$;-^dummy\.dat$"", only I did it something like "+\.csv$;-^Test\.csv$". The zip was containing all csv files that are in a source folder plus Test.csv one as well.

    The question is: if FileFilter parm is supposed to be RegEx expression why it doesn't recognize "^" character as the beginning of the line? What FileFilter should be used to compress only the "Test.csv" file (an exact match search on the file name)?

     

    Filed under:
  • 07-08-2009 1:31 AM In reply to

    • dimon
    • Not Ranked
    • Joined on 07-02-2009
    • Posts 4

    Re: FastZip: Using FileFilter to zip a single file (exact match) in .Net 3.5

    anyone? library creators?

  • 07-13-2009 8:25 AM In reply to

    Re: FastZip: Using FileFilter to zip a single file (exact match) in .Net 3.5

    Hi

    Had a quick look. The FileSystemScanner,ScanDir code is using System.IO.Directory.GetFiles(directory);

    and the help for this says "File names include the full path. "

    So try coding as if matching the full name including path. Probably need to escape the backslash with a double. E.g. @"\\Test.csv$".

    Seems a bit odd to me; I would have done it as you have done. Let us know how you get on.

  • 07-13-2009 7:56 PM In reply to

    • dimon
    • Not Ranked
    • Joined on 07-02-2009
    • Posts 4

    Re: FastZip: Using FileFilter to zip a single file (exact match) in .Net 3.5

    As I stated in my first post I tried it as well, it didn't work for me. I ended up using ZipOutputStream and ZipEntry classes.

     

  • 07-14-2009 1:06 AM In reply to

    Re: FastZip: Using FileFilter to zip a single file (exact match) in .Net 3.5

    dimon:
    As I stated in my first post I tried it as well

    Missed that - yes it was quite clear on a re-read. Sorry.

    Good move using the ZipOutputStream/ZipEntry, you get much more control.

  • 12-05-2009 1:58 PM In reply to

    Re: FastZip: Using FileFilter to zip a single file (exact match) in .Net 3.5

    Found this thread via web search while facing the same problem.

    So for g* sake here is the solution which works (at least for me):

    Regex.Escape(

    "\\" & filename) which will translate to "\\\\" & filename.

    If you ask why, I realy only can guess. Perhaps the lib does unescape 2x before parsing regex?

  • 12-07-2009 2:56 AM In reply to

    Re: FastZip: Using FileFilter to zip a single file (exact match) in .Net 3.5

    That's good insight you've given us there. Thanks for that.

    I have not looked closely at the filename parsing code.  Your comments highlight an interesting point on the doco as quoted in the first post ...

    The following expression includes all name ending in '.dat' with the exception of 'dummy.dat': "+\.dat$;-^dummy\.dat$""

    That usage of +(regex);-(regex) is, I believe, an additional "wrapper" that means that the string is not a straightforward regex string. I think that the + and - (minus)  are specially treated by our code. But I could be wrong; perhaps its standard regex I've not encountered before.

     

Page 1 of 1 (7 items)
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this (fleischfalle@alphasierrapapa.com) email address.