-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathselectiveCopy.py
More file actions
26 lines (20 loc) · 785 Bytes
/
selectiveCopy.py
File metadata and controls
26 lines (20 loc) · 785 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/python3
# walks through a folder tree and searches for files with .py file extension. Archive these files in to a ZIP file
import os, sys, shutil
from zipfile import ZipFile
def main(dir):
dir = '/home/iliya/repository'
zip_file = os.path.join(dir, 'python_scripts.zip')
extension = '.py'
backup(dir, zip_file, extension)
print('Destination ZIP file: %s' % zip_file)
def backup(dir, zip_file, extension):
with ZipFile(zip_file, 'w') as zip:
for dirname, subdirs, basename in os.walk(dir):
lst = [x for x in basename if x.endswith(extension)]
if len(lst) > 0:
for file in lst:
zip.write(os.path.join(dirname, file))
zip.close()
if __name__ == '__main__':
main(dir)