Тема: trash-box
use files, array
const TRASH_DIR = "E:\\trash-box\\"; // Папка для хранение файлов.
function scan(path, whosearch)
res = [];
path = path + "\\";
if index(lower(path), "system") = -1 and
index(lower(path), lower(..TRASH_DIR + whosearch + "\\")) = - 1 then
for f in files.scan(path + "*."+ whosearch) do
append(res, path + lower(f))
end;
for f in files.scan(path, files.dir) do
res = array.concat(res, scan(path + f, whosearch))
end
end;
return res
end
roots = files.roots();
array.remove(roots, len(roots) - 1)
for whosearch in files.scan(..TRASH_DIR, files.dir) do
print "." + whosearch + " ...";
trash = [];
count = 0;
for r in roots do
try
trash = array.concat(trash, scan(r, whosearch))
catch e by
print r + e
end;
end;
for file in trash do
try
files.copy(file, ..TRASH_DIR + whosearch + "\\");
files.delete(file);
count ++;
catch error by
print file + " not copied: " + error;
end;
end;
print count, "copied.", "All", len(trash) + ".";
end;Идея такая, в папке TRASH_DIR мы создаем папки которые будут означать расширения которые будут туда складываться.
Например в папке TRASH_DIR создадим папку txt, и запустим скрипт, все файлы с расширением txt будут сложены в эту папку, но при этом файлы в этой папке не будут в следующий раз обрабатываться. Так же этот скрипт не задевает системные файлы и файлы которые нельзя открыть.
Внимание: Оригинальные файлы удаляются.
Удобно если файлов одного типа стало очень много. Мне пригодилось для сортировки моей попойки на карте памяти.