Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import os
- import sys
- print(os.getlogin())
- from_path = "C:\\users\\" + os.getlogin()
- to = sys.argv[1]
- def start():
- if len(sys.argv) > 0:
- if os.path.isdir(to):
- print("Path to set to: "+to)
- print("Searching for files...")
- cluster_files = []
- cluster_indexes = []
- cluster_sorted = []
- size = 0
- for dirname, dirnames, filenames in os.walk(from_path):
- if(not dirname.startswith(".")):
- for filename in filenames:
- path = os.path.join(dirname, filename)
- if(not filename.startswith(".")):
- try:
- crr_size = get_size(path)
- size += crr_size
- add = True
- except:
- print("File '" + path + "': permission denied")
- add = False
- if(add):
- cluster_files.append(path)
- cluster_indexes.append(int(crr_size))
- else:
- print("File '" + path + "': no need to copy this file")
- else:
- print("Dir '" + dirname + "': no need to copy this dir")
- print("--------------------------------------------------")
- print("Sorting files by size.")
- cluster_sorted = sort_files(list(cluster_indexes), list(cluster_files))
- print("Sorting finished.")
- print("Cluster length: " + str(len(cluster_sorted)))
- print("File size in GB: " + str(float((((size)/1024)/1024)/1024)))
- last_size = 0
- good = 0
- badd = 0
- for a in cluster_sorted:
- if(get_size(a) >= last_size):
- good += 1
- else:
- badd += 1
- last_size = get_size(a)
- else:
- print(to + " is not a directory.")
- else:
- print("Missing an argument")
- def get_size(filename):
- try:
- st = os.stat(filename)
- return st.st_size
- except:
- print("File has not been found")
- def sort_files(array_indexes, array_files):#from http://stackoverflow.com/questions/18262306/quick-sort-with-python edited by me lol
- less = []
- equal = []
- greater = []
- if len(array_indexes) > 1:
- pivot = array_indexes[0]
- index = 0
- for x in list(array_indexes):
- if x < pivot:
- less.append(array_files[index])
- if x == pivot:
- equal.append(array_files[index])
- if x > pivot:
- greater.append(array_files[index])
- index += index
- return sort_files(less, array_files)+equal+sort_files(greater, array_files)
- else:
- return array_files
- start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement