ChangeFileAttrib()
Previous  Top  Next

:ChangeFileAttrib() - Change a specific (File) Entry's File Attributes.

Syntax

:ChangeFileAttrib(<cEntry> | <nEntry> | <oEntry>,  
                  <cNewFileAttributes>) --> cOldFileAttributes  

Parameters

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.  
 
<cNewFileAttributes>  
<cNewFileAttributes> specifies the New File Attributes for the existing (File) Entry, as a string that can contain any of the following possible letters: "ADHRS", but may also be empty. Other characters are simply ignored.  

Returns

This method returns the previous, old, File Attributes, or "" (an empty string), if the (File) Entry could not be found or no File Attributes were set.  

Description

This method changes the File Attributes of an existing (File) Entry in the Zip File to a new value, and returns the previous, old, File Attributes of the Entry. If only individual File Attributes need to be set or removed, but all other existing File Attributes of the (File) Entry should be retained, then those original File Attributes must be explicitly set, too, or they will be removed!  
 
Valid File Attribute letters are:  
·"A" for "Archive",  
·"D" for "Directory",  
·"H" for "Hidden",  
·"R" for "Read-Only",  
·"S" for "System".  
 
In addition, the letter "V" for "Volume" could be set, but is not appropriate for zip files, and will be ignored!  
 
Setting or removing the "D" Attribute (for Directories), will convert the (File) Entry to/from a Directory! This means that any Data that might be associated with the (File) Entry will be ignored when the Zip File is extracted, if the Entry is changed to a Directory (by setting the "D" File Attribute)!  
 
Future versions might allow the update of single File Attributes independently, without having to manually set the other Attributes to the previous, original, value. This could be accomplished by setting the default value to the existing File Attribute value of the (File) Entry, and adding another parameter to the method, which would indicate if the submitted File Attribute should be considered the absolute value (as it is currently the case), or if the given File Attribute letter(s) should be added to or removed from the existing, original, File Attribute value.  
 
NOTE: The supported File Attributes are ONLY valid for MS DOS and Windows (FAT/VFAT/NTFS)!  

Example

Open an existing Zip File named "MyArchive.zip" and read its directory into an array. Then remove the "Read-Only" File Attribute from all the File Entries that might have it set (but keep all other File Attributes as they are). Then save the changes and close the Zip File:  
 
oZip := XbZLibZip():New('MyArchive.zip')  
aDir := oZip:Directory()  
for nCount := 1 to len(aDir)  
   cFAttr := XbZ_DosAttrib2FileAttrib(aDir[nCount]:ExternalFAttrib)  
   if 'R' $ cFAttr  
      oZip:ChangeFileAttrib(aDir[nCount], StrTran(cFAttr, 'R', ''))  
   endif  
next nCount  
oZip:Close()