Jump to content


Photo

Unlinking *.whatever


  • Please log in to reply
4 replies to this topic

#1 ibanez270dx

ibanez270dx
  • Members
  • PipPipPip
  • Advanced Member
  • 53 posts

Posted 14 August 2006 - 03:29 PM

Hi,
I'm trying to do an unlink command like so: unlink(*.xls) . It doesn't work and I have tried it with single and double quotes. Can anyone help me?

Thanks!
- Jeff

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 14 August 2006 - 03:35 PM

Use the glob() function to generate an array of all .xls files in a folder.

Loop through the array and unlink each one separately.
Legend has it that reading the manual never killed anyone.
My site

#3 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 14 August 2006 - 03:43 PM

try this.

$dir = "path/to/folder";

foreach (glob($dir . "*.xls") as $files) {
     unlink($files);
}

Hope this helps,
Tom

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#4 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 14 August 2006 - 03:50 PM

You have to be careful with this. It will delete all of the files with the ext of xls in that folder and all sub folders.

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#5 ibanez270dx

ibanez270dx
  • Members
  • PipPipPip
  • Advanced Member
  • 53 posts

Posted 14 August 2006 - 04:04 PM

Thanks! I used this:

foreach (glob("*.xls") as $filename)
	{
   	 unlink($filename);
	}

It works perfectly. And yes, I did need to delete all the files with a *.xls extension.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users