ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Main Area and Open Discussion > General Software Discussion

Recreate files but without content to target drive

<< < (6/11) > >>

Alright fellas,

2 hours spent trying to fix the script and here are the results for the python script!

--- ---08:25:33 PM
08:25:46 PM
a grand total of 13 seconds!!!

Zipfile about 12 MB. with 54827 files (created a few files since last count)

Things I had to fix:
 modified time errors
 path length exceeded errors

 #set time to unix epoch 0 = 'Thu Jan 01 07:00:00 1970'
so there will be some files with incorrect timestamps in the zipfile

--- End quote ---

I hope this helps everyone... though I still got some warnings while running the script... probably due to windows handling of files and or paths... DeprecationWarning: struct integer overflow masking is deprecated
  zf.fp.write(zinfo.FileHeader()) DeprecationWarning: 'H' format requires 0 <= number <= 65535
  zf.fp.write(zinfo.FileHeader()) DeprecationWarning: struct integer overflow masking is deprecated
  zf.close() DeprecationWarning: 'H' format requires 0 <= number <= 65535
--- End quote ---

Here's the final code so far

--- Code: Python ---#!/usr/bin/pythonimport os, sys, zipfile, optparse, zlib, fnmatch, time optp=optparse.OptionParser(usage="%prog [options] <target-zip> <source-dir> [<source-dir...>]")optp.add_option("-x", help="exclude mask", action="append", dest="exclude", default=[])optp.add_option("-q", help="be quiet", action="store_true", dest="quiet", default=False)optp.add_option("-e", help="omit empty directories", action="store_true", dest="omit_empty", default=False)err=optp.error options, args = optp.parse_args() if len(args)<2:  optp.print_usage()  sys.exit(1)  zf=zipfile.ZipFile(args[0], "w") def zfAddNullFile(zf, arcname, date_time, extattr=0):  """ Adapted from the method in zipfile """  arcname = os.path.normpath(os.path.splitdrive(arcname)[1])  arcname = arcname.lstrip(os.sep + (os.altsep or ""))  zinfo = zipfile.ZipInfo(arcname, date_time)  zinfo.external_attr = extattr  zinfo.compress_type = zf.compression  zinfo.file_size = 0  zinfo.flag_bits = 0x00  zinfo.header_offset = zf.fp.tell()    # Start of header bytes  zf._writecheck(zinfo)  zf._didModify = True  zinfo.CRC = CRC = zlib.crc32("")  zinfo.compress_size = 0  zinfo.file_size = 0  zf.fp.write(zinfo.FileHeader())  zf.filelist.append(zinfo)  zf.NameToInfo[zinfo.filename] = zinfo  def printFilename(f, msg=None):  if not options.quiet:    if msg:      print msg,        try:      print f    except:      print f.encode("charmap", "replace") for sourceDir in args[1:]:  try:    sourceDir=sourceDir.decode("latin-1")  except:    print sourceDir    print "Exception while trying to process directory"  for dp, dn, fn in os.walk(sourceDir):    if fn:      for f in fn:        f=os.path.join(dp, f)        ok=True        for xmask in options.exclude:          if fnmatch.fnmatch(f, xmask):            ok=False            break        if ok:          try:            mtime=time.localtime(os.stat(f).st_mtime)          except ValueError:            print "Error: Modified time out of range."            printFilename(f)            print os.stat(f).st_mtime            mtime=time.localtime(0) #set time to unix epoch 0 = 'Thu Jan 01 07:00:00 1970'          except WindowsError:            print "Error: Can't find file due to windows limitations."            printFilename(f)            mtime=time.localtime(0) #set time to unix epoch 0 = 'Thu Jan 01 07:00:00 1970'                      zfAddNullFile(zf, f, (mtime.tm_year, mtime.tm_mon, mtime.tm_mday, mtime.tm_hour, mtime.tm_min, mtime.tm_sec))    elif not options.omit_empty:      mtime=time.localtime(os.stat(dp).st_mtime)      #printFilename(dp, "(empty directory)")      zfAddNullFile(zf, dp, (mtime.tm_year, mtime.tm_mon, mtime.tm_mday, mtime.tm_hour, mtime.tm_min, mtime.tm_sec), 16)      zf.close()print "All Done."
I hope you all enjoy this. I'll attach the exe as well, though I can't make any guarantees for it.

Nice job, vixay.   :D

Hey guys, love the software in here.  I am currently using zero zipper to create the 0 byte files but I was wondering if there were any command line options that I could use so that I could utilize zero zipper in a batch file.

I tried to use vixay's exe, but i'm not sure I completely understand how to use it.

Thanks for your help

You should be able to use vixay's exe for what you want to do on the commandline like this:

makeTreeZip.exe mydir1 mydir2

Let us know how that works out for you.

Website | Download
v1.0.5 - 2011-10-24
    + Zero Zipper now preserves both the modified and created timestamps for
      files and folders within the zipfile.  (Thanks, Wayne)
    + Added drag-n-drop to the two edit fields.  (Thanks, Wayne)
    ! Fixed 120 DPI display issues.  (Thanks, Wayne)
    ! Fixed a parsing issue where not all files would get cloned into the zip.


[0] Message Index

[#] Next page

[*] Previous page

Go to full version