need to add folder not the contains using this lib

Just starting out? Need help? Post your questions and find answers here.
Micko
Enthusiast
Enthusiast
Posts: 244
Joined: Thu May 24, 2007 7:36 pm
Location: Senegal
Contact:

need to add folder not the contains using this lib

Post by Micko »

Code: Select all

Procedure Add2ZIP(Chemin.s, Fichiers.s) 
  Protected Rep.l, entre.s 
  If Not Right(Chemin, 1) = "\" : Chemin+"\" : EndIf 
  If Not Right(Fichiers, 1) = "\" : Fichiers+"\" : EndIf 
  Debug Chemin 
  Rep = ExamineDirectory(#PB_Any, Chemin, "") 
  If Rep 
    While NextDirectoryEntry(Rep) 
      entre = DirectoryEntryName(Rep)  
      If entre = "." Or entre = ".." 
        Continue 
      ElseIf DirectoryEntryType(Rep) = #PB_DirectoryEntry_File 
        PureZIP_Archive_Compress(RemoveString(Chemin+entre, Fichiers), #True) 
        Debug "ZIP: "+RemoveString(Chemin+entre, Fichiers)+" ("+Str(FileSize(Chemin+entre))+")" 
      Else 
        Add2ZIP(Chemin+entre+"\", Fichiers) 
      EndIf 
    Wend 
    FinishDirectory(Rep) 
  EndIf 
EndProcedure 

Archive$ = "C:\Archive.zip" 
RepSource$ = "C:\Temp\" 
;SetCurrentDirectory_(@RepSource$) 

If PureZIP_Archive_Create(Archive$, #APPEND_STATUS_CREATE) 
  Add2ZIP(RepSource$, RepSource$) 
  PureZIP_Archive_Close() : CloseWindow(Window_0) 
EndIf
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Re: need to add folder not the contains using this lib

Post by gnozal »

Micko wrote:need to add folder not the contains using this lib

Code: Select all

;
; Create TEST.ZIP with an empty directory structure
;
; |- Purebasic400
;         |
;         |- Compilers
;         |- PureLibraries
;                 |
;                 |-UserLibraries
;
If PureZIP_Archive_Create("c:\test.zip", #APPEND_STATUS_CREATE)
  PureZIP_Archive_Compress("c:\purebasic400", #True)
  PureZIP_Archive_Compress("c:\purebasic400\Compilers", #True)
  PureZIP_Archive_Compress("c:\purebasic400\PureLibraries", #True)
  PureZIP_Archive_Compress("c:\purebasic400\PureLibraries\UserLibraries", #True)
  PureZIP_Archive_Close()
EndIf
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
byo
Enthusiast
Enthusiast
Posts: 635
Joined: Mon Apr 02, 2007 1:43 am
Location: Brazil

Post by byo »

Hmm... I was wondering that myself, earlier today.
Thanks for clearing it up, gnozal.
Your lib works as a charm.
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

Note that some unzip programs do not create empty directories, so better place
a dummy file inside if the creation of the directory must be ensured.
quidquid Latine dictum sit altum videtur
Micko
Enthusiast
Enthusiast
Posts: 244
Joined: Thu May 24, 2007 7:36 pm
Location: Senegal
Contact:

Post by Micko »

@ Freak thank for this information

@gnozal
this snippet create an empty directory in archive file but if want to add the Purebasic400 directory(with all folders) in archive like your sample how can i do it using the procedure in my first post ?

note: not the directory contains only, but the directory and all files

Code: Select all

|- Purebasic400 
;         | 
;         |- Compilers 
;         |- PureLibraries 
;                 | 
;                 |-UserLibraries 
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

2Micko/SpaceMan?
Micko wrote:note: not the directory contains only, but the directory and all files
Micko wrote:need to add folder not the contains
It's not very clear what you want to do ...?

- Easy way to add files + folder recursively : PureZIP_AddFiles()
- Adding individual files : PureZIP_AddFile(), or PureZIP_Archive_Create/Compress/Close()
To add the path or not, PureZIP provides enough flags (#PureZIP_DontStorePath, #PureZIP_StorePathAbsolute, #PureZIP_StorePathRelative) and options.

Sorry, but I can't do all the job for you.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
Micko
Enthusiast
Enthusiast
Posts: 244
Joined: Thu May 24, 2007 7:36 pm
Location: Senegal
Contact:

Post by Micko »

hi gnozal
It's not very clear what you want to do ...?
just add folder and all contains files to zip

but i hav do it i will post the code next

2Micko/SpaceMan?
i hav some trouble when create the profile but i will change to the same nick
thanks
Micko
Enthusiast
Enthusiast
Posts: 244
Joined: Thu May 24, 2007 7:36 pm
Location: Senegal
Contact:

Post by Micko »

Hi Guys
Why this procedure won't work ? :shock:

Code: Select all

Procedure Add2Zip(Path.s) 
  Protected dir.l, entry.s,Rep.s,chaine.s
  If Not Right(Path, 1) = "\" : Path+"\" : EndIf 
  dir = ExamineDirectory(#PB_Any, Path, ""): Debug Path
  If dir 
    Rep = LSet(Path, 3)
    chaine = RemoveString(Path, Rep)
    ; Debug chaine
    While NextDirectoryEntry(dir) 
      entry = DirectoryEntryName(dir)  
      If entry = "." Or entry = ".." 
        Continue 
      ElseIf DirectoryEntryType(dir) = #PB_DirectoryEntry_File
        PureZIP_Archive_Compress(RemoveString(Path, Rep)+entry,#True) 
      Else 
        Add2Zip(Path+entry+"\")
    EndIf : Wend 
    FinishDirectory(dir) 
  EndIf 
EndProcedure

SourceDir$ = "c:\Temp"
destination$ = "C:\Test.ZIP"
If PureZIP_Archive_Create(destination$, #APPEND_STATUS_CREATE)
  Add2Zip(SourceDir$)
  PureZIP_Archive_Close()
Micko
Enthusiast
Enthusiast
Posts: 244
Joined: Thu May 24, 2007 7:36 pm
Location: Senegal
Contact:

Post by Micko »

Hi
i hav do it like this and it work great :D

Code: Select all

Procedure Add2ZIP(Path.s) 
  Protected dir.l, entry.s, Rep.s, chaine.s
  If Not Right(Path, 1) = "\" : Path+"\" : EndIf 
  dir = ExamineDirectory(#PB_Any, Path, "")
  If dir 
    While NextDirectoryEntry(dir) 
      entry = DirectoryEntryName(dir)  
      If entry = "." Or entry = ".." 
        Continue 
      ElseIf DirectoryEntryType(dir) = #PB_DirectoryEntry_File
        PureZIP_Archive_Compress(Path+entry,#True)
      Else 
        Add2ZIP(Path+entry+"\")
    EndIf : Wend 
    FinishDirectory(dir) 
  EndIf 
EndProcedure

SourceDir$ = "c:\Temp"
destination$ = "C:\Test.ZIP"
If PureZIP_Archive_Create(destination$, #APPEND_STATUS_CREATE)
  Add2ZIP(SourceDir$)
  PureZIP_Archive_Close()
Note:modified from Thorsten1867 original code
shire
User
User
Posts: 46
Joined: Mon Jul 25, 2011 5:24 am

Re: need to add folder not the contains using this lib

Post by shire »

Hello,

PureZip has this function:

Code: Select all

PureZIP_AddFiles("C:\Test.ZIP", "C:\File\*.*", #PureZIP_StorePathAbsolute, #PureZIP_Recursive)
and it works the same way as your function

Code: Select all

Procedure Add2ZIP(Path.s)
EndProcedure
:)
Post Reply