ChangeFileName()
|
Previous Top Next |
:ChangeFileName(<cEntry> | <nEntry> | <oEntry>,
|
<cNewFileName>) --> cOldName
|
The first Parameter can be either a Character String, a Number, or a Central Directory Record Object:
|
<cEntry>
|
<cEntry> specifies the File Name of the Central Directory Record Entry that contains the information for the (File) Entry that should be changed in the Zip File.
|
|
<nEntry>
|
<nEntry> specifies the Index Number of the Central Directory Record Entry that contains the information for the (File) Entry that should be changed in the Zip File.
|
|
<oEntry>
|
<oEntry> specifies the ZipCentralDirectoryRecord object of the (File) Entry that should be changed in the Zip File.
|
<cNewFileName>
|
<cNewFileName> specifies the New File Name for the existing (File) Entry.
|
This method returns the previous, old, File Name, or "" (an empty string) if the (File) Entry could not be found.
|
This method changes the File Name of an existing (File) Entry in the Zip File, and returns the previous, old, File Name of the Entry. If the new File Name has a different length than the old one, and the Entry is not the last (File) Entry in the Zip File, all following (File) Entries will be adjusted, and moved accordingly. If the (File) Entry could not be found, an empty string will be returned, and nothing is changed.
|
|
This method allows the changing of any Zip File Entry's (File) Name to virtually any other File Name. The only exception is that the new File Name cannot be an empty string. But it is possible to assign the same File Name to more than one (File) Entry, or to change the case of a File Name -- which might be significant for other Operating Systems, like LINUX -- or to move the File from/into a (virtual) Directory, by removing/adding a relative path in front of the existing File Name.
|
|
With this method it is also possible to create multiple (File) Entries in the Zip File that have the (exact) same File Name, or might contain characters that are not allowed in File Names (which is OS-dependent)! If this is done (inadvertently or on purpose), it could create problems with the automatic Extraction of Files in the :ExtractAll() and/or :Extract() methods, and could also interfere with the :Test() and :Fix() methods, as all of them rely on unique (and valid) File Names in the Zip File! Other programs (like PkZip, PkUnZip, PkZipFix, WinZip, PowerArchiver, etc.) that access such Zip Files might encounter the same type of problems!
|
Open an existing Zip File named "MyArchive.zip" and read its directory into an array. Then change the File Name of each (File) Entry in that Zip File to be prefixed with "NewDir\", so that each Entry will be (virtually) moved into a new directory named "NewDir". Then save the changes and close the Zip File:
|
|
oZip := XbZLibZip():New('MyArchive.zip')
|
aDir := oZip:Directory()
|
AEval(aDir, {|oR| oZip:ChangeFileName(oR, 'NewDir\' + oR:FileName)}
|
oZip:Close()
|