Code Monkey home page Code Monkey logo

alex-zhang.github.io's Introduction


🌟 Star us on GitHub — it helps!

alex-zhang.github.io's People

Contributors

alex-zhang avatar

alex-zhang.github.io's Issues

设置zip中的文件在Windows下的隐藏属性

有的时候需要在mac或linux的server生成一写window用的zip资源,但是

https://msdn.microsoft.com/en-us/library/windows/desktop/gg258117(v=vs.85).aspx

··· python

#!/usr/bin/python

-- coding: utf-8 --

import sys
import os
import zipfile
import shutil

inputZipPath = os.path.normpath(str(sys.argv[1]))

print 'inputZipPath', inputZipPath
print '-----------------------------------'

inputZipDirPath = os.path.dirname(inputZipPath)
inputZipBasename = os.path.basename(inputZipPath)
inputTempZipPath = os.path.join(inputZipDirPath, '__' + inputZipBasename)

shutil.copyfile(inputZipPath, inputTempZipPath)
print 'copy temp file to', inputTempZipPath

with zipfile.ZipFile(inputTempZipPath, 'r', zipfile.ZIP_DEFLATED) as inputTargetZip:
with zipfile.ZipFile(inputZipPath, 'w', zipfile.ZIP_DEFLATED) as outputTargetZip:
for inputfileinfo in inputTargetZip.infolist():
inputfilename = inputfileinfo.filename
inputfileIsDir = inputfilename.endswith('/')
inputfilenameDepth = len(inputfilename.split('/'))
if inputfileIsDir: inputfilenameDepth -= 1
inputfilebasename = os.path.basename(inputfilename)
inputfilepurename = os.path.splitext(inputfilebasename)[0]
inputfileextname = os.path.splitext(inputfilebasename)[1]

  # print inputfilename
  # print inputfilenameDepth

  #we make the fake create_system
  inputfileinfo.create_system = 0

  if inputfilenameDepth == 2:
    if(inputfileIsDir or
      (inputfileextname != '.exe' and
      inputfileextname != '.pdf')):

      # http://stackoverflow.com/questions/434641/how-do-i-set-permissions-attributes-on-a-file-in-a-zip-file-using-pythons-zip/6297838#6297838
      # http://unix.stackexchange.com/questions/14705/the-zip-formats-external-file-attribute
      # https://msdn.microsoft.com/en-us/library/windows/desktop/gg258117(v=vs.85).aspx

      print inputfilename
      print hex(inputfileinfo.external_attr)

      #inputfileinfo.external_attr = inputfileinfo.external_attr | 0x2

      #print inputfileinfo.create_system

      if(inputfileIsDir):
        inputfileinfo.external_attr = 0x12
      else:
        inputfileinfo.external_attr = 0x2

      print 'change to'
      print hex(inputfileinfo.external_attr)

  outputTargetZip.writestr(inputfileinfo, inputTargetZip.read(inputfilename))

os.remove(inputTempZipPath)

···

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.