This forum has been archived. All content is frozen. Please use KDE Discuss instead.

How to create an archive from a folder?

Tags: None
(comma "," separated)
Tupla
Registered Member
Posts
47
Karma
0
OS
Hello everybody, I was trying to write a simple program that compress a user-specified folder, but I don't know how to create the archive. I gave a look at KArchive class and its subclasses, but still it's not clear.
As for the type of compression, I'd like to use either tar.gz, tar.bz2 or zip.

Thanks
olligod
Registered Member
Posts
1
Karma
0
OS
If you want to write a front end to the shell command, the command is

Code: Select all
/bin/tar jcf archivename.tar.bz2 directoryname


The letter "j" sends it all through bz2 compression.
Alternatively, "z" would be the gz compression.

It will do the job recursively for you through the subdir-structure.
I believe you'd use full paths for archive and directory to be compressed.


I do not know whether there is a letter for zip compression.
There is always another syntax for archiving/compression with piping (key | ) where one command pipes its output into the next: in that case the commands being tar and zip, including there options/flags.
But you would have to figure that one out...


Have fun.
panzi
Registered Member
Posts
8
Karma
0
Or enter these URLs into konqueror for more information:
    man:tar
    man:zip
    man:7za
Tupla
Registered Member
Posts
47
Karma
0
OS
Ok, thank you very much for the tips! Can you please tell me how to execute commands in my program? Do I have to use something like system("command"), or is there another way to do that?
User avatar
anda_skoa
KDE Developer
Posts
783
Karma
4
OS
I haven't used this API myself yet, but from the documentation my guess would be like this:

Code: Select all
KZip archive( "filename.zip" );
archive.open( QIODevice::WriteOnly );
archive.addLocalDirectory( "directoryname", "how-it-should-be-named-in-the-zip" );
archive.close();


Cheers,
_


anda_skoa, proud to be a member of KDE forums since 2008-Oct.
Tupla
Registered Member
Posts
47
Karma
0
OS
Yeah, I guessed the same thing and tried it in tar.gz (adding mimetype to archive constructor), but then my program "freezed"...
It wasn't freeze, my program was compressing a big size folder because of an error in path settings...
Now it works with KArchive API, thanks everyone for your quick answers! :)


Bookmarks



Who is online

Registered users: Bing [Bot], blue_bullet, Google [Bot], rockscient, Yahoo [Bot]