Skip to content

Instantly share code, notes, and snippets.

@jalexandre0
Last active December 16, 2015 15:09
Show Gist options
  • Save jalexandre0/5454189 to your computer and use it in GitHub Desktop.
Save jalexandre0/5454189 to your computer and use it in GitHub Desktop.
File counter to use when your run low of inodes and your system has only one partition. It is ugly, unpolished, unfinished and works perfectly for me ;)
#!/usr/bin/env python
import os
import sys
root_dir = str(sys.argv[1])
total = 0
def look_dirs(root_dir):
dir_list = []
for dirs in os.listdir(root_dir):
dir_list.append(os.path.join(root_dir,dirs))
return dir_list
def count_files(dir_list):
file_number = []
for (path, dirs, files) in os.walk(dir_list):
for file_name in files:
if os.path.isfile(os.path.join(path, file_name)):
file_number.append(file_name)
return len(file_number)
for dirs in look_dirs(root_dir):
if os.path.isdir(dirs):
print str(dirs) + " " + str(count_files(dirs))
total += count_files(dirs)
print "Total " + str(total)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment