Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import sys
- # If empty paramater
- if len(sys.argv) == 1:
- exit()
- # Set path
- path = sys.argv[-1]
- # Set option(s)
- if len(sys.argv) > 1:
- commandArgs = sys.argv[1:-1]
- items = []
- for (dirpath, folders, files) in os.walk(path):
- if dirpath == path or '-R' in commandArgs:
- for item in (files + folders):
- if item[0] != '.' or ('-a' in commandArgs and item[0] == '.'):
- if '-d' in commandArgs:
- if not os.path.isfile(dirpath + '/' + item):
- list_files = [i for i in os.listdir(
- dirpath + '/' + item) if os.path.isfile(dirpath + '/' + item + '/' + i)]
- number_files = len(list_files)
- items.append(
- item + ' ' + str(number_files) + ' (Files)')
- elif '-l' in commandArgs:
- if os.path.isfile(dirpath + '/' + item):
- size_file = os.path.getsize(dirpath + '/' + item)
- items.append(item + ' ' + str(size_file) + ' Bite(s)')
- elif '-c' in commandArgs:
- if os.path.isfile(dirpath + '/' + item):
- my_file = open(dirpath + '/' + item, 'r')
- number_line = sum([1 for row in my_file])
- items.append(
- item + ' ' + str(number_line) + ' Line(s)')
- else:
- items.append(item)
- if '-r' in commandArgs:
- items = list(reversed(items))
- for i in items:
- print(i)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement