Forum Moderators: coopster

Message Too Old, No Replies

deleting entire contents of a folder

         

lindajames

1:09 pm on Aug 18, 2003 (gmt 0)

10+ Year Member



hello, i have a folder called "temp" that a script of mine uses to write temporary data to. i want to create a little script that when executed the script deletes all the files within that "temp" folder. can anyone assist me on how this can be done?

cheers

Paul in South Africa

1:26 pm on Aug 18, 2003 (gmt 0)

10+ Year Member



Might need a bit of refinement but should provide a basis to work from.

$dh = opendir(temp) or die ("Could not open temp directory");
while (false!== ($file = readdir($dh)))
{
if ($file!= "." && $file!= "..")
{
unlink("temp/$file")
}
}

lindajames

2:12 pm on Aug 18, 2003 (gmt 0)

10+ Year Member



i tried that but seems to not work, could it be because i am using windows IIS server?

Paul in South Africa

2:47 pm on Aug 18, 2003 (gmt 0)

10+ Year Member



I'm not sure about IIS, I've never used it.

One thing I noticed is that I left the ; off after the unlink(temp/$file);

The other thing you could try is to echo $file to make sure that it is actually reading the directory listing.

lindajames

3:34 pm on Aug 18, 2003 (gmt 0)

10+ Year Member



i guess the problem was with the missing ; it seems to work now. thanks