как я архивирую целое дерево папки в Unix, но только определенные файлы?

Можно добавить атрибуты к функции и использовать ее в качестве статической переменной.

def myfunc():
  myfunc.counter += 1
  print myfunc.counter

# attribute must be initialized
myfunc.counter = 0

, С другой стороны, если Вы не хотите устанавливать переменную вне функции, можно использовать hasattr() для предотвращения AttributeError исключение:

def myfunc():
  if not hasattr(myfunc, "counter"):
     myfunc.counter = 0  # it doesn't exist yet, so initialize it
  myfunc.counter += 1

Так или иначе статические переменные довольно редки, и необходимо найти лучшее место для этой переменной, скорее всего, в классе.

43
задан raven 30 November 2009 в 14:03
поделиться

6 ответов

Перейдите в папку веб-сайта, затем запустите

zip -R foo '*.php' '*.html' '*.js' '*.css' 

Вы также можете запустить это вне папки веб-сайта:

zip -r foo website_folder -i '*.php' '*.html' '*.js' '*.css'
67
ответ дан 26 November 2019 в 22:41
поделиться

You can use find and grep to generate the file list, then pipe that into zip

e.g.

find . | egrep "\.(html|css|js|php)$" | zip -@ test.zip

(-@ tells zip to read a file list from stdin)

21
ответ дан 26 November 2019 в 22:41
поделиться

Вот как я справился для этого, но мне также нравится версия ghostdog74.

tar -czvf archive.tgz `find  test/ | egrep ".*\.html|.*\.php"`

Вы можете добавить дополнительные расширения, добавив их в регулярное выражение.

7
ответ дан 26 November 2019 в 22:41
поделиться

I liked Nick's answer, but, since this is a programming site, why not use Ant to do this. :)

Then you can put in a parameter so that different types of files can be zipped up.

http://ant.apache.org/manual/Tasks/zip.html

4
ответ дан 26 November 2019 в 22:41
поделиться

You could write a shell script to copy files based on a pattern/expression into a new folder, zip the contents and then delete the folder. Now, as for the actual syntax of it, ill leave that to you :D.

1
ответ дан 26 November 2019 в 22:41
поделиться

you may want to use find(GNU) to find all your php,html etc files.then tar them up

find /path -type f \( -iname "*.php" -o -iname "*.css" -o -iname "*.js" -o -iname "*.ext" \) -exec tar -r --file=test.tar "{}" +;

after that you can zip it up

3
ответ дан 26 November 2019 в 22:41
поделиться
Другие вопросы по тегам:

Похожие вопросы: