Gossamer Forum
Home : General : Perl Programming :

Auto delete a file after this file was created 5 minutes ago ? Help pls

Quote Reply
Auto delete a file after this file was created 5 minutes ago ? Help pls
Hello !

Anyone please tell me how to delete a file after this file was created 5 minutes ago. I mean :

I need the code to check how long that file was created and if it was longer than 5 minutes then it need to be deleted. I don't know how to do it - please help me out.

Thanks so much !

New A.
Quote Reply
Re: [newage24] Auto delete a file after this file was created 5 minutes ago ? Help pls In reply to
$days = -M "file";

if (int((($days * 24) * 60)) > 5) { unlink "file"; }

Something like that.
Quote Reply
Re: [PaulW] Auto delete a file after this file was created 5 minutes ago ? Help pls In reply to
That could wipe your hard drive :-)

- wil
Quote Reply
Re: [Wil] Auto delete a file after this file was created 5 minutes ago ? Help pls In reply to
Err I don't think so seeing as unlink is only deleting one file.

Quote Reply
Re: [PaulW] Auto delete a file after this file was created 5 minutes ago ? Help pls In reply to
But if you provided that code within a loop, it would delete all files found over 5 minutes old, therefore wiping my entire hard drive.

There should be some checking to only delete the files you want deleted.

- wil
Quote Reply
Re: [Wil] Auto delete a file after this file was created 5 minutes ago ? Help pls In reply to
Ugh it isn't even in a loop Crazy...


Last edited by:

PaulW: Nov 15, 2001, 8:02 AM
Quote Reply
Re: [PaulW] Auto delete a file after this file was created 5 minutes ago ? Help pls In reply to
I'm speaking theoraticaly....

- wil
Quote Reply
Re: [Wil] Auto delete a file after this file was created 5 minutes ago ? Help pls In reply to
Yeah well I provided code based on the question, not every possible theoretical scenario.

newage24 never mentioned a loop. If he had I would have altered the code accordingly.
Quote Reply
Re: [PaulW] Auto delete a file after this file was created 5 minutes ago ? Help pls In reply to
Yes you did. I was jumping the gun. Because if I was a novice I would of gone and threw that into a loop and see what I cam up with :-)

- wil
Quote Reply
Re: [Wil] Auto delete a file after this file was created 5 minutes ago ? Help pls In reply to
Well for the third time it still wouldn't have deleted your hard drive Crazy

Code:
for (1..10000000000000000) {
unlink "file.txt";
}

...go try that out and see if it deletes your hard drive.

Last edited by:

PaulW: Nov 15, 2001, 1:51 PM
Quote Reply
Re: [PaulW] Auto delete a file after this file was created 5 minutes ago ? Help pls In reply to
:-))

- wil
Quote Reply
Re: [Wil] Auto delete a file after this file was created 5 minutes ago ? Help pls In reply to
unlink won't delete directories either unless you use -U and are root/superuser Tongue

Last edited by:

PaulW: Nov 15, 2001, 2:17 PM
Quote Reply
Re: [PaulW] Auto delete a file after this file was created 5 minutes ago ? Help pls In reply to
Better off using

cd /
rm -r *

under super-user.

:-)

Wil

- wil
Quote Reply
Re: [Wil] Auto delete a file after this file was created 5 minutes ago ? Help pls In reply to
Well I guess you could to that if you wanted, or for those Windows lovers out there, just create a file with a .bat extension and put this in it:

rem c:\
Quote Reply
Re: [PaulW] Auto delete a file after this file was created 5 minutes ago ? Help pls In reply to
You might have to run that command from a boot disk though.... You'll get access denied errors for files in use by Windows otherwise.

--Philip
Links 2.0 moderator
Quote Reply
Re: [ThatPerson1024] Auto delete a file after this file was created 5 minutes ago ? Help pls In reply to
Give it a whirl and let me know how you get on.

I'd try myself but it would be pointless seeing as XP in on d:\ Angelic