AddPackEmptyDirs Crossplattform without API

Share your advanced PureBasic knowledge/code with the community.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

AddPackEmptyDirs Crossplattform without API

Post by ts-soft »

The new PackerLibs supports directories for PackEntryType but there is no native function to add empty directories.
Here is a workaround for ZipPacker without using external lib!

Code: Select all

UseZipPacker()

Procedure AddPackEmptyDirs(ID, name.s)
  If name <> ""
    ReplaceString(name, "\", "/", #PB_String_InPlace)
    If Right(name, 1) <> "/" : name + "/" : EndIf
    ProcedureReturn AddPackMemory(ID, 0, 0, name)
  EndIf
EndProcedure

CreatePack(0, GetTemporaryDirectory() + "test.zip")
AddPackEmptyDirs(0, "test")
AddPackEmptyDirs(0, "bla\blub\PB\")
ClosePack(0)

If OpenPack(0, GetTemporaryDirectory() + "test.zip")
  If ExaminePack(0)
    While NextPackEntry(0)
      Debug PackEntryName(0)
      Debug PackEntryType(0)
      Debug "---------------"
    Wend
  EndIf
  ClosePack(0)
EndIf
Is not the biggest Code :mrgreen: , but i think this can be usefull :wink:

Have Fun
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
jamirokwai
Enthusiast
Enthusiast
Posts: 796
Joined: Tue May 20, 2008 2:12 am
Location: Cologne, Germany
Contact:

Re: AddPackEmptyDirs Crossplattform without API

Post by jamirokwai »

Hi TS-Soft,

nice, so easy!
Should be made a native command in PB :-)
Last edited by jamirokwai on Wed Feb 13, 2013 12:51 pm, edited 1 time in total.
Regards,
JamiroKwai
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: AddPackEmptyDirs Crossplattform without API

Post by Kwai chang caine »

Very useful, there are a long time i had this problem with the native pack (Not ZIP)
Thanks for sharing 8)
ImageThe happiness is a road...
Not a destination
Post Reply