Recent

Author Topic: zip and unzip archives  (Read 13214 times)

Mangafreak1995

  • New Member
  • *
  • Posts: 25
zip and unzip archives
« on: September 29, 2010, 11:46:56 pm »
Hey lazarus-guys,

I'm using a TProcess to execute the 'zip' and 'unzip' command. But it doesn't work fine. Unzipping works very well, but when I execute sth like this : 'zip /home/myname/desktop/file.zip /tmp/myapp/' it zips but it contains only the folder tmp -> myapp. When I execute this : 'zip -r /home/myname/desktop/file.zip /tmp/myapp/' it zips everything in the /tmp/myapp/ folder but in the archive there are also those two subdirectories again. I want the files from the folder /tmp/myapp/ in the archive without subdirectories (but the subdirs of /tmp/myapp/). What am I doing wrong or what param makes this working ?

Mangafreak1995

fabienwang

  • Sr. Member
  • ****
  • Posts: 449
  • Lazarus is the best
    • My blog
Re: zip and unzip archives
« Reply #1 on: September 30, 2010, 12:23:30 am »
I'm using Arch Linux.
Known for: CPickSniff, OpenGrabby
Contributed to: LazPaint

Mangafreak1995

  • New Member
  • *
  • Posts: 25
Re: zip and unzip archives
« Reply #2 on: September 30, 2010, 06:11:27 am »
Installation was easy and without any problems.
When I make a zipfile using this code:
Code: [Select]
var dir : String;
    ZipFile : TZipFile;
begin
     try
        dir := GetTempDir + 'working';
        ForceDirectories(dir);
        Img.Picture.PNG.SaveToFile(dir + '/img1.png');
        Img1.Picture.PNG.SaveToFile(dir + '/img2.png');
        ZipFile.FileName := strFile;
        ZipFile.Activate();
        ZipFile.AppendFileFromDisk(dir + '/img1.png', ZipFile.FileName);
        ZipFile.AppendFileFromDisk(dir + '/img2.png', ZipFile.FileName);
        ZipFile.Active := false;
     except
           // ...
I get an error when I wan to open this zipfile with the Archivemanager.
Quote
Archive:  /home/myname/Desktop/myarchive.zip
[/home/myname/Desktop/myarchive.zip]
  End-of-central-directory signature not found.  Either this file is not
  a zipfile, or it constitutes one disk of a multi-part archive.  In the
  latter case the central directory and zipfile comment will be found on
  the last disk(s) of this archive.
zipinfo:  cannot find zipfile directory in one of /home/myname/Desktop/myarchive.zip or
          /home/myname/Desktop/myarchive.zip, and cannot find /home/myname/Desktop/myarchive.zip, period.

Ocye

  • Hero Member
  • *****
  • Posts: 518
    • Scrabble3D
Re: zip and unzip archives
« Reply #3 on: September 30, 2010, 10:29:10 am »
zip /home/myname/desktop/file.zip /tmp/myapp/*
Lazarus 1.7 (SVN) FPC 3.0.0

Mangafreak1995

  • New Member
  • *
  • Posts: 25
Re: zip and unzip archives
« Reply #4 on: September 30, 2010, 04:33:07 pm »
thanks  ;D

Mangafreak1995

  • New Member
  • *
  • Posts: 25
Re: zip and unzip archives
« Reply #5 on: September 30, 2010, 07:24:14 pm »
well, or not. It's the same problem. But I found some kind of documentation: http://linux.about.com/od/commands/l/blcmdl1_zip.htm.
I used the param -j . This makes zip ignore the pathes and only takes the files without any directory-prefixes.

My current code is :
Code: [Select]
// PathIt is a function replacing the spaces(' ') with '\ '
// ExecuteProcess makes a process executing the query and wait until it's done
// strFile : String = file to create or replace
// dir : TempDir (in this case '/tmp/') + 'appname'
ShowMessage('zip -jr ' + PathIt(strFile) + ' ' + dir + '*');
ExecuteProcess('zip -jr ' + PathIt(strFile) + ' ' + dir + '*');
When I copy the command from the messagebox and paste it into the console it works. But executeprocess doesnt work :(
« Last Edit: September 30, 2010, 07:33:50 pm by Mangafreak1995 »

Ocye

  • Hero Member
  • *****
  • Posts: 518
    • Scrabble3D
Re: zip and unzip archives
« Reply #6 on: October 01, 2010, 11:10:48 am »
ExecuteProcess() reveals errorcode in the result, and maybe raises error as well. All other "doesn't work" advisements are crystal-ball-reading.
If you don't use ZIP deliberately you should take GZIP into account. It's available on all Linux in contrast to ZIP which often needs to be installed extra.
Lazarus 1.7 (SVN) FPC 3.0.0

 

TinyPortal © 2005-2018