WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: 1bosborn on February 27, 2015, 05:02:11 AM

Title: zZipFiles error deleting files
Post by: 1bosborn on February 27, 2015, 05:02:11 AM
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?
Title: Re: zZipFiles error deleting files
Post by: td on February 27, 2015, 06:41:48 AM
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. 
Title: Re: zZipFiles error deleting files
Post by: 1bosborn on February 27, 2015, 08:27:47 AM
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.
Title: Re: zZipFiles error deleting files
Post by: td on February 27, 2015, 09:35:50 AM
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.
Title: Re: zZipFiles error deleting files
Post by: 1bosborn on February 27, 2015, 01:00:47 PM
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.
Title: Re: zZipFiles error deleting files
Post by: td on February 27, 2015, 01:56:06 PM
Don't think you are the first nor likely the last to stick something outside a loop structure that rightfully belongs inside one.