Click to See Complete Forum and Search --> : Deleting files using wildcards?
Mike Burdick
06-08-2007, 09:36 PM
Hi,
I'm not too sure how to delete files using wildcards. For example: I would like to delete all the .gif files in a directory called temp. Is this how it is done?
unlink(<temp/*.gif>);
...or should it be inside some sort of loop?
Thanks...
Mike Burdick
06-10-2007, 03:47 AM
Well...
This is what I ended up using - good, bad, or indifferent - it works.
I was a little timid playing with wild cards lest make a mistake and lose some valuable files:eek:
#Path to my files. Company that hosts your site will tell
#you the exact path. But if you put the files there, you'll
#already know this.
#This will delete all the .gif files located in the temp directory.
$filepath= "somedirectory/somethingelse/temp/*.gif";
@mylist=glob($filepath);
unlink @mylist;
Jeff Mott
06-10-2007, 10:01 AM
Don't worry, Mike. You did it exactly right.
Mike Burdick
06-10-2007, 05:33 PM
Thanks Jeff,
I had these visions of losing my all the gif files and wanted to seek advise before trying something - so backed up everything before "flipping the switch" (don't ask me how I learned this). :D Better safe than sorry!