Author Topic: [SOLVED] unlink with wildcard?  (Read 6100 times)

0 Members and 1 Guest are viewing this topic.

Offline MadTechie

  • Guru
  • Freak!
  • *
  • Posts: 9,374
  • Gender: Male
  • I try to F1
    • View Profile
Re: unlink with wildcard?
« Reply #15 on: June 12, 2009, 07:11:29 PM »
Just tested my code.. worked fine on WinXP (not saying much I know) no errors
Computers are good at following instructions, but not at reading your mind.
The quality of a response, is usually directly related to the quality of the question. ©2009 mjdamato
I dunno about that.  A regular expression has a 0% chance of touching my penis.
the code is professionally made up but not working
Remember to Click Solved, how to ask questions - the smart way

Offline acctmanTopic starter

  • Devotee
  • Posts: 560
    • View Profile
Re: unlink with wildcard?
« Reply #16 on: June 12, 2009, 07:14:00 PM »
thanks

Offline thebadbad

  • Addict
  • Posts: 1,610
  • Gender: Male
  • $me = str_replace($question, $answer, $post);
    • View Profile
Re: unlink with wildcard?
« Reply #17 on: June 12, 2009, 07:36:42 PM »
Just tested my code.. worked fine on WinXP (not saying much I know) no errors

Made me test it too, and yeah, it works when you wrap unlink in a user function. Weird though, can't explain why it's okay with that, but fails with the built-in function.

Edit: Actually, I think I got it: unlink() takes a stream resource as an optional second parameter. When array_walk() sends the array key as the second parameter, unlink() fails, because it expects a stream resource, but gets an integer or string. When your function myunlink() receives the second parameter, it simply ignores it (=not resulting in a fatal error).
« Last Edit: June 12, 2009, 07:44:46 PM by thebadbad »

Offline tastro

  • Enthusiast
  • Posts: 105
    • View Profile
    • tAsTrO
Re: [SOLVED] unlink with wildcard?
« Reply #18 on: February 14, 2010, 12:28:43 PM »
this works just fine for me on xp:

$dir = "/yourdirectory/";
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false){
if(
preg_match("/yourregex./ismU", $file))){echo "filename:".$file."\n";unlink($file);}
}
closedir($dh);
}
}
« Last Edit: February 14, 2010, 12:34:10 PM by tastro »
Tastro - Free Downloads http://www.tastro.com/