Hard Light Productions Forums

Off-Topic Discussion => Programming => Topic started by: Sandwich on February 28, 2009, 06:19:41 pm

Title: PHP Coding Help
Post by: Sandwich on February 28, 2009, 06:19:41 pm
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:

Code: [Select]
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. :p Any takers?
Title: Re: PHP Coding Help
Post by: Spicious on February 28, 2009, 11:14:15 pm
Two things: Programming forum; Python.

I'd suggest making a backup first or setting list_only to True. It's using the last modified time for sorting. Change mtime to ctime or atime to use creation time (on windows) or access time respectively.

[attachment deleted by admin]
Title: Re: PHP Coding Help
Post by: Sandwich on March 01, 2009, 07:18:47 am
Uhm... how does one run a Python script?
Title: Re: PHP Coding Help
Post by: The E on March 01, 2009, 07:32:11 am
Go here (http://www.python.org/download/). Download the 2.6.1 binaries and install them. The installer should register the appropriate shell extensions, which should allow the to run the script just by doubleclicking on them.

EDIT: Seems I was wrong about that. You need to right-click the script, select "Open with...", and then select the python.exe. Should work then.