Forum Moderators: coopster

Message Too Old, No Replies

Automatic remove of File

how do i remove a file, if the size is >100 k

         

bastil

8:06 pm on May 8, 2003 (gmt 0)

10+ Year Member



hows the code for a script what watches f.e. the file list.txt and automatically removes it, if its getting bigger than 100kb?

lorax

1:29 am on May 9, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



What script language and do you want to trim the file down or outright delete the whole file?

daisho

1:29 am on May 9, 2003 (gmt 0)

10+ Year Member



In PHP:

<?
$filename='/blah/blah/testfile.txt';

$maxsize=102400;

if( filesize($filename)>$maxsize ) {
unlink($filename);
}

?>

daisho.

ShawnR

2:31 am on May 9, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just to state the obvious: You can't have anything 'watch' your file unless you have higher level system access, such as access to cron. If your script is the only thing writing to the file, that shouldn't matter, and Daisho's suggestion will do fine.

Shawn

bastil

1:24 pm on May 9, 2003 (gmt 0)

10+ Year Member



sorry, really forgot to tell what language i need :) i make all my scripts in perl. I would enter the code in another script which writes the file. So everytime it wants to write into file it would check the size before and delete it, if its getting to big

bastil

1:25 pm on May 9, 2003 (gmt 0)

10+ Year Member



thx daisho for the code

lorax

2:18 pm on May 9, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Ah. PERL - well you'll need to wait for a PERL expert - which I am not. Sorry.

ShawnR

10:20 pm on May 9, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Not a perl expert either, but here is how:

$filename='/blah/blah/testfile.txt';

$maxsize=102400;

if ( -s $filename > $maxsize ) {
unlink($filename);
}

Shawn