forked from DedSecInside/Awesome-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsorted_files.py
41 lines (31 loc) · 1.11 KB
/
sorted_files.py
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import os
print "Choose an option - "
print "1. N largest files. "
print "2. N smallest files. "
print "3. N most recently used files. "
print "4. N least recently used files. "
option = input("Your option?\n")
directory = raw_input("Absolute path of directory\n")
N = input("Number of files you want to list?\n")
files = os.listdir(directory)
def list_N_files(all_files):
"""
Lists all files
Args:
all_files: (str): write your description
"""
print "\n".join(all_files[:N])
if option==1:
sorted_file_list = sorted(files, key=lambda x: os.stat(os.path.join(directory, x)).st_size, reverse=True)
list_N_files(sorted_file_list)
elif option == 2:
sorted_file_list = sorted(files, key=lambda x: os.stat(os.path.join(directory, x)).st_size )
list_N_files(sorted_file_list)
elif option == 3:
sorted_file_list = sorted(files, key=lambda x: os.stat(os.path.join(directory, x)).st_mtime, reverse=True)
list_N_files(sorted_file_list)
elif option == 4:
sorted_file_list = sorted(files, key=lambda x: os.stat(os.path.join(directory, x)).st_mtime)
list_N_files(sorted_file_list)
else:
print("Invalid option")