First, some backstory. I retain all my downloads in a folder, with as many subfolders under that as needed for categorization. Downloads\Graphics\Photoshop Plugins\, Downloads\Tools\File Utilities\, Downloads\Games\FS2\, etc. I then try to keep an eye on the size of the downloads folder, and when it reaches a certain size (used to be 700Mb, but now it's 4.2Gb or so), I archive the entire folder to disc and clean it out. However, I've been slack, and now I have around 7Gb of files in there.
What I'd like to do is get a script that will parse through the entire directory structure, making a list of each file's date, size, and location. It would then sort that list by date, and - oldest first - start adding up the filesizes until it got to the specified total size (4.2Gb). It would then take that list of files, and move each of those files to that file's relative position under a new "to-burn" folder (replacing the downloads folder in the file's path).
What I'd be left with is a "to-burn" folder with <=4.2Gb of files, where none of those files are newer than any of the files in the "downloads" folder.
In pseudo-code, I'd think it'd be something like this:
TARGETSIZE = 4.2Gb
For each FILE
{
get DATE
get SIZE
get relative PATH
}
Store FILE in array LIST
Sort LIST by FILE[DATE]
For each FILE in LIST
{
TOTALSIZE = TOTALSIZE + FILE[SIZE]
while TOTALSIZE <= TARGETSIZE
{
move FILE to ".\to-burn\" . FILE[PATH]
}
}
I'd prefer if this was in PHP, since then I'd be able to understand it.
Any takers?