Page 1 of 1
need to add folder not the contains using this lib
Posted: Tue Aug 28, 2007 4:02 pm
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
Re: need to add folder not the contains using this lib
Posted: Tue Aug 28, 2007 4:16 pm
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
Posted: Tue Aug 28, 2007 5:40 pm
by byo
Hmm... I was wondering that myself, earlier today.
Thanks for clearing it up, gnozal.
Your lib works as a charm.
Posted: Tue Aug 28, 2007 7:15 pm
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.
Posted: Tue Aug 28, 2007 11:05 pm
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
Posted: Wed Aug 29, 2007 8:35 am
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.
Posted: Wed Aug 29, 2007 5:10 pm
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
Posted: Fri Aug 31, 2007 8:39 pm
by Micko
Hi Guys
Why this procedure won't work ?
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()
Posted: Sat Sep 01, 2007 11:32 pm
by Micko
Hi
i hav do it like this and it work great
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
Re: need to add folder not the contains using this lib
Posted: Sat Feb 11, 2012 9:06 am
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
