Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zipping a folder

I am trying to use

TZipFile.ZipDirectoryContents()

Like so:

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

If I am reading this right, it should save the contents of folder "workingdir" into a file named 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 confuse me:

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

  2. It says cannot access file. Is this because it's not created yet? Am I using this function wong? If so how would I create a zip file from a folder location?

like image 783
Glen Morse Avatar asked Jun 16 '12 23:06

Glen Morse


People also ask

How do I work with zipped files and folders?

In Windows, you work with zipped files and folders in the same way that you work with uncompressed files and folders. Combine several files into a single zipped folder to more easily share a group of files. To zip (compress) a file or folder Locate the file or folder that you want to zip.

How do I Zip a file in Windows 10?

In Windows, you work with zipped files and folders in the same way that you work with uncompressed files and folders. ... To zip (compress) a file or folder. Locate the file or folder that you want to zip. Press and hold (or right-click) the file or folder, select (or point to) Send to, and then select Compressed (zipped) folder.

How do I convert a folder to a zip file?

How to convert folder to ZIP file? Under " Select folder to compress ", click on browse (or your browser equivalent) Select the folder you wish to zip. (Optional) Set the desired compression level by clicking the down arrow next to "Zip Folder". Click "Zip Folder". It will start compressing the ...

How do I unzip a single file or folder?

Locate the zipped folder that you want to unzip (extract) files or folders from. To unzip a single file or folder, open the zipped folder, then drag the file or folder from the zipped folder to a new location.


1 Answers

I tested your code and it failed in the same way as you reported.

I then created an empty zip file manually by running WinZip.

Then ran your code and it ran fine.

It appears that the zip file has to already exist for ZipDirectoryContents to work.

To create a zip file programatically:

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

This line will then work:

  TZipFile.ZipDirectoryContents('c:\myfolder\newzipfile.zip', WorkingDir);
like image 160
RobertFrank Avatar answered Sep 28 '22 08:09

RobertFrank