zZipFiles error deleting files

Started by 1bosborn, February 27, 2015, 05:02:11 AM

Previous topic - Next topic

1bosborn

I am using zZipFiles to archive several (6) fairly small text data files at the end of a script. It successfully creates the archive and deletes 4 of the files but fails to delete the same 2 files every time. My code looks like this:

ftbalist = FileItemize("*.csv|*.tsv|*.psv") ; itemize tsv's and csv's for archive
ftbacount = ItemCount(ftbalist, @Tab)
suffix = 1
zipdate = StrReplace(Strfix(TimeYmdHms(), " ", 10), ":", "_") ;get the file date and convert colons to underscores
target = "archive\%zipdate%_%suffix%.zip"
While FileExist(target)
   suffix = suffix + 1
   target = "archive\%zipdate%_%suffix%.zip"
EndWhile
zipsuccess = zZipFiles("m", target, ftbalist, "")

and the error looks like this:

0     adding: N192StickerExpires2015-03.csv (152 bytes security) (deflated 74%)     adding: N192StickerExpires2015-04.csv (152 bytes security) (deflated 74%)     adding: N192StickerExpires2015-05.csv (152 bytes security) (deflated 74%)     adding: not_sent.tsv (152 bytes security) (deflated 64%)     adding: sent.tsv (152 bytes security) (deflated 65%)     adding: serindex-email.tsv (152 bytes security) (deflated 60%)      zip warning: error deleting N192StickerExpires2015-03.csv      zip warning: error deleting N192StickerExpires2015-04.csv   

As I mentioned, it's always the same two that fail. I'm running Win7, there is no space problem on the drive and I tried compiling it and running it on a different machine running XP with the same result.
Any ideas?

td

You didn't indicate which version of the extender you are using but check the NTFS permissions of the files that error on attempted deletion.  You can use Explorer's file 'Properties' context menu's security tab to find your current permissions on the file. 
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

1bosborn

Sorry about that. I have Winbatch 2014A, I am adding the extender via;
AddExtender("WWZIP44I.DLL",0,"WWZIP64I.DLL")
I don't think it's an NTFS permissions problem as I put them there before the script runs and am able to delete the files manually after the script finishes.

td

Neither 'putting them there' nor 'deleting them manually  after the script finishes' completely eliminates the possibility of NTFS permission problems.

But assuming that it isn't a NTFS permission problem, it could be a that another process has the files open without sharing enabled.  If you were using the latest version of WinBatch you could simply use the FileLockItemize function to confirm or eliminate this as a cause.  Another possible cause is that the files have the 'read-only' attribute.   If I recall correctly, the extender will not delete a file that is marked with the 'read-only' attribute.  You would need to remove the 'read-only' attribute before archiving the files in that case.

Other than that you could just delete the files after the fact using FileDelete instead of using the 'm' option.   Note that the 'FileDelete' will not delete a file that has the read-only attribute set either.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

1bosborn

You got me!
Your statement about another process having them locked made me realize I was using a For-Next loop to cycle through the files and my FileClose statement was after the loop so only the last file was being closed (and therefore deleted). I moved the FileClose statement inside the loop, just before the Next statement and it's working as expected.
Thanks for your help.

td

Don't think you are the first nor likely the last to stick something outside a loop structure that rightfully belongs inside one.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade