Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env rdmd
- import std.stdio;
- import std.getopt;
- import std.file;
- import std.array;
- import std.algorithm.iteration;
- import std.algorithm.sorting;
- string folder; //путь к папке
- uint limit; //предел
- int main(string[] args)
- {
- auto helpInfo = getopt(
- args,
- "f|folder", "Folder path", &folder,
- "l|limit", "Limit in megabytes", &limit
- );
- if (!limit || !folder || helpInfo.helpWanted) {
- defaultGetoptPrinter("Removes old files while space limit is exceeded.\nParams:", helpInfo.options);
- return 0;
- }
- DirEntry[] entries = dirEntries(folder, SpanMode.shallow).filter!(f => f.isFile).array;
- entries.sort!((x,y) => x.timeLastModified < y.timeLastModified);
- ulong total = entries.map!(f => f.size).sum;
- while (total > limit*1024*1024) {
- total -= entries[0].size;
- remove(entries[0].name);
- entries = entries[1..$];
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement