2017-06-05 2 views
1

Y at-il un moyen de décompresser un seul fichier à partir d'un zip? J'utilise code basé sur response pour How to get Inno Setup to unzip a file it installed (all as part of the one installation process), fonctionne parfaitement pour Décompressez mais n'ont pas une idée comment peut-il décompressez un seul fichier:Comment obtenir Inno Setup pour décompresser un seul fichier?

[Code]: 

const 
    NO_PROGRESS_BOX = 4; 
    RESPOND_YES_TO_ALL = 16; 

procedure UnZip(ZipPath, TargetPath: string); 
var 
    Shell: Variant; 
    ZipFile: Variant; 
    TargetFolder: Variant; 
begin 
    Shell := CreateOleObject('Shell.Application'); 

    ZipFile := Shell.NameSpace(ZipPath); 
    if VarIsClear(ZipFile) then 
    RaiseException(Format('ZIP file "%s" does not exist or cannot be opened', [ZipPath])); 

    TargetFolder := Shell.NameSpace(TargetPath); 
    if VarIsClear(TargetFolder) then 
    RaiseException(Format('Target path "%s" does not exist', [TargetPath])); 

    TargetFolder.CopyHere(ZipFile.Items, NO_PROGRESS_BOX or RESPOND_YES_TO_ALL); 
end; 

Répondre

1

Utilisez Folder.ParseName pour récupérer une référence à un fichier spécifique dans une archive ZIP « dossier ». Passez ensuite cette référence à Folder.CopyHere pour l'extraire.

const 
    NO_PROGRESS_BOX = 4; 
    RESPOND_YES_TO_ALL = 16; 

procedure UnZip(ZipPath, FileName, TargetPath: string); 
var 
    Shell: Variant; 
    ZipFile: Variant; 
    Item: Variant; 
    TargetFolder: Variant; 
begin 
    Shell := CreateOleObject('Shell.Application'); 

    ZipFile := Shell.NameSpace(ZipPath); 
    if VarIsClear(ZipFile) then 
    RaiseException(Format('ZIP file "%s" does not exist or cannot be opened', [ZipPath])); 

    Item := ZipFile.ParseName(FileName); 
    if VarIsClear(Item) then 
    RaiseException(Format('ZIP file "%s" does not contain file "%s"', [ZipPath, FileName])); 

    TargetFolder := Shell.NameSpace(TargetPath); 
    if VarIsClear(TargetFolder) then 
    RaiseException(Format('Target path "%s" does not exist', [TargetPath])); 

    TargetFolder.CopyHere(Item, NO_PROGRESS_BOX or RESPOND_YES_TO_ALL); 
end; 
+0

Merci, fonctionne parfaitement. –

1

J'ai trouvé une manière qui fonctionne, pas ce que je pensais mais est fonctionnel.

UnZip(AppFolder+'\modulos\seimpresoras-2.2.zip', tmpFolder); 
FileCopy(tmpFolder+'\seimpresoras\resources\default.properties', AppFolder+'\printers.properties', False);