Pin folder

I'm trying to use

TZipFile.ZipDirectoryContents() 

Same:

 TZipFile.ZipDirectoryContents('Test.PCF', WorkingDir); 

If I read this correctly, it should save the contents of the "workingdir" folder to a file called Test.pcf.

Now when I do this, I get error ::

 Raised exception class EFOpenError with message Cannot open file ...test.pcf. The process cannot access the file because its being used by another process." 

Two things mix me up:

  • It says that he cannot open the file. There is no test.pcf yet. I was hoping this would create it.

  • He says that he cannot access the file. Is it because it is not created yet? Do I use this feature for long? If so, how do I create a zip file from a folder?

+7
source share
1 answer

I checked your code and it failed just as you reported.

Then I created an empty mail file manually by running WinZip.

Then I ran your code and it went fine.

It looks like a zip file must already exist for ZipDirectoryContents to work.

To create a zip file programmatically:

  myZipFile := TZIpFile.Create; myZipFile.Open('c:\myfolder\newzipfile.zip', TZipMode.zmWrite); myZipFile.Close; myZipFile.Free; 

This line will work:

  TZipFile.ZipDirectoryContents('c:\myfolder\newzipfile.zip', WorkingDir); 
+14
source

All Articles