Skip to content

Commit 77a8d38

Browse files
committedJul 24, 2015
Merge pull request #1908 from getnikola/fix-1873
remove empty directories with --clean-files
2 parents 8151c2d + 7c205be commit 77a8d38

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed
 

‎CHANGES.txt

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ New in master
44
Features
55
--------
66

7+
* Remove empty directories with nikola check --clean-files (Issue #1873)
8+
79
Bugfixes
810
--------
911

‎nikola/plugins/command/check.py

+14
Original file line numberDiff line numberDiff line change
@@ -313,5 +313,19 @@ def scan_files(self):
313313
def clean_files(self):
314314
only_on_output, _ = real_scan_files(self.site)
315315
for f in only_on_output:
316+
self.logger.info('removed: {0}'.format(f))
316317
os.unlink(f)
318+
319+
# Find empty directories and remove them
320+
output_folder = self.site.config['OUTPUT_FOLDER']
321+
all_dirs = []
322+
for root, dirs, files in os.walk(output_folder, followlinks=True):
323+
all_dirs.append(root)
324+
all_dirs.sort(key=len, reverse=True)
325+
for d in all_dirs:
326+
try:
327+
os.rmdir(d)
328+
self.logger.info('removed: {0}/'.format(d))
329+
except OSError:
330+
pass
317331
return True

0 commit comments

Comments
 (0)
Please sign in to comment.