Author Topic: PHP Coding Help  (Read 1949 times)

0 Members and 1 Guest are viewing this topic.

Offline Sandwich

  • Got Screen?
  • 213
    • Minecraft
    • Skype
    • Steam
    • Twitter
    • Brainzipper
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?
SERIOUSLY...! | {The Sandvich Bar} - Rhino-FS2 Tutorial | CapShip Turret Upgrade | The Complete FS2 Ship List | System Background Package

"...The quintessential quality of our age is that of dreams coming true. Just think of it. For centuries we have dreamt of flying; recently we made that come true: we have always hankered for speed; now we have speeds greater than we can stand: we wanted to speak to far parts of the Earth; we can: we wanted to explore the sea bottom; we have: and so  on, and so on: and, too, we wanted the power to smash our enemies utterly; we have it. If we had truly wanted peace, we should have had that as well. But true peace has never been one of the genuine dreams - we have got little further than preaching against war in order to appease our consciences. The truly wishful dreams, the many-minded dreams are now irresistible - they become facts." - 'The Outward Urge' by John Wyndham

"The very essence of tolerance rests on the fact that we have to be intolerant of intolerance. Stretching right back to Kant, through the Frankfurt School and up to today, liberalism means that we can do anything we like as long as we don't hurt others. This means that if we are tolerant of others' intolerance - especially when that intolerance is a call for genocide - then all we are doing is allowing that intolerance to flourish, and allowing the violence that will spring from that intolerance to continue unabated." - Bren Carlill

 

Offline Spicious

  • Master Chief John-158
  • 210
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]

 

Offline Sandwich

  • Got Screen?
  • 213
    • Minecraft
    • Skype
    • Steam
    • Twitter
    • Brainzipper
Uhm... how does one run a Python script?
SERIOUSLY...! | {The Sandvich Bar} - Rhino-FS2 Tutorial | CapShip Turret Upgrade | The Complete FS2 Ship List | System Background Package

"...The quintessential quality of our age is that of dreams coming true. Just think of it. For centuries we have dreamt of flying; recently we made that come true: we have always hankered for speed; now we have speeds greater than we can stand: we wanted to speak to far parts of the Earth; we can: we wanted to explore the sea bottom; we have: and so  on, and so on: and, too, we wanted the power to smash our enemies utterly; we have it. If we had truly wanted peace, we should have had that as well. But true peace has never been one of the genuine dreams - we have got little further than preaching against war in order to appease our consciences. The truly wishful dreams, the many-minded dreams are now irresistible - they become facts." - 'The Outward Urge' by John Wyndham

"The very essence of tolerance rests on the fact that we have to be intolerant of intolerance. Stretching right back to Kant, through the Frankfurt School and up to today, liberalism means that we can do anything we like as long as we don't hurt others. This means that if we are tolerant of others' intolerance - especially when that intolerance is a call for genocide - then all we are doing is allowing that intolerance to flourish, and allowing the violence that will spring from that intolerance to continue unabated." - Bren Carlill

 

Offline The E

  • He's Ebeneezer Goode
  • 213
  • Nothing personal, just tech support.
    • Steam
    • Twitter
Go here. 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.
« Last Edit: March 01, 2009, 07:35:33 am by The E »
If I'm just aching this can't go on
I came from chasing dreams to feel alone
There must be changes, miss to feel strong
I really need lifе to touch me
--Evergrey, Where August Mourns