Potreboval by som na to nejaký skript asi však?...neviete niečo o tom ?
OS mám Ubuntu 16.04
Ďakujem za odpovede majstri!
Kód: Vybrať všetko
import os
import ntpath
import shutil
from shutil import copyfile as copy
import random
conf = dict({})
conf["dir"] = "files"
conf["n"] = 5
def get_size(filename):
return os.stat(filename).st_size
f_counter = 0
dir_counter = 1
current_dir = os.path.dirname(os.path.realpath(__file__))
directory, file_list = current_dir + "/" + conf["dir"], []
for path, subdirs, files in os.walk(directory):
for name in files:
file_list.append([os.path.join(path, name), get_size(os.path.join(path, name))])
file_list = sorted(file_list, key=lambda x: x[1])
if not os.path.isdir("./sorted"):
os.mkdir("./sorted", 0o755)
else:
print("Warning: directory \"./sorted\" already exists")
for item in file_list:
if f_counter % conf["n"] == 0:
nxt = current_dir + "/sorted/" + str(dir_counter)
if os.path.isdir(nxt):
shutil.rmtree(nxt)
os.mkdir(nxt, 0o755)
dir_counter += 1
to = current_dir + "/sorted/" + str(dir_counter - 1) + "/" + str(random.random()) + "_" + str(
ntpath.basename(item[0]))
copy(item[0], to)
f_counter += 1