RE: Autorename extracted files from zip-archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> -----Original Message-----
> From: Merlin Morgenstern [mailto:merlin_x@xxxxxxxxxxx]
> Sent: Wednesday, January 19, 2011 6:06 AM
> To: php-general@xxxxxxxxxxxxx
> Subject:  Autorename extracted files from zip-archive
> 
> Hello,
> 
> I am using shell_exec to uncompress zip files which works fine, but has
one
> big problem. Whenever the zip-archive containes an already existing file
> name, it will overwrite the current one. I need the file to be extracted
and
> autorenamed.
> 
> This is the code line:
> 
> 	$output = shell_exec('unzip -jo '.$filename.' -d '.$path);
> 
> Does anybody know a way on how to autorename existing files?
> 
> I thought about a workaround on extracting to a tmp folder and then moving
> to the proper directory while renaming the files if they already exists.
> Unfortunatelly I could not find a way to do this.
> 
> Thank you for any help on this.
> 
> Merlin
> 

Merlin,

It's a shame that unzip doesn't have that feature like unrar.  However, I
suggest you extract the contents of the zip files into a temp working
directory.  Scan the files within that directory for any compressed archives
and extract each into their own subdirectory matching the filename.  And
just recurse until no more compressed archives.  Then process whatever files
you need.  When done, just rm -fd <tmpworkdir>  (my unix/linux is limited.
Don't recall the parameters).  That way, clean up is a synch and you still
have the original file when there's something wrong during processing stages
like mismatch columns, duplicate entries, etc.

Regards,
Tommy


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux