Skip to content

Commit

Permalink
Skip special files and directories during backup
Browse files Browse the repository at this point in the history
  • Loading branch information
AcidWeb committed Mar 18, 2019
1 parent cd04ae1 commit 6d65360
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions CB/Core.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def init_config(self):
'Backup': {'Enabled': True, 'Number': 7},
'Version': __version__}
self.save_config()
if not os.path.isdir('WTF-Backup'):
if not os.path.isdir('WTF-Backup') and self.config['Backup']['Enabled']:
os.mkdir('WTF-Backup')
self.update_config()

Expand Down Expand Up @@ -170,9 +170,15 @@ def backup_check(self):
def backup_wtf(self):
zipf = zipfile.ZipFile(f'WTF-Backup\\{datetime.datetime.now().strftime("%d%m%y")}.zip', 'w',
zipfile.ZIP_DEFLATED)
filecount = sum([len(files) for r, d, files in os.walk('WTF/')])
filecount = 0
for root, dirs, files in os.walk('WTF/', topdown=True):
files = [f for f in files if not f[0] == '.']
dirs[:] = [d for d in dirs if not d[0] == '.']
filecount += len(files)
with tqdm(total=filecount, bar_format='{n_fmt}/{total_fmt} |{bar}|') as pbar:
for root, dirs, files in os.walk('WTF/'):
for root, dirs, files in os.walk('WTF/', topdown=True):
files = [f for f in files if not f[0] == '.']
dirs[:] = [d for d in dirs if not d[0] == '.']
for f in files:
zipf.write(os.path.join(root, f))
pbar.update(1)
Expand Down

0 comments on commit 6d65360

Please sign in to comment.