UNLINK MULTIPLE

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
roadkillbunny
New php-forum User
New php-forum User
Posts: 9
Joined: Sat Mar 22, 2003 4:03 pm
Contact:

Sat Mar 22, 2003 8:41 pm

Is there a way I can delete multiple files(in one directory)?
RoadkillBunny

Visit me at http://www.middleoftheroad.tk

Oleg Butuzov
Last Samuray
Last Samuray
Posts: 824
Joined: Sun Jun 02, 2002 3:09 am

Sat Mar 22, 2003 11:42 pm

1) read a dir
2) unlink a files

roadkillbunny
New php-forum User
New php-forum User
Posts: 9
Joined: Sat Mar 22, 2003 4:03 pm
Contact:

Sun Mar 23, 2003 10:10 am

I treid unlink("filename/*");
with the files having permissions of 777.
Is that what I am supposed to do?
RoadkillBunny

Visit me at http://www.middleoftheroad.tk

*JaH*
New php-forum User
New php-forum User
Posts: 80
Joined: Fri Jan 31, 2003 4:18 pm

Sun Mar 23, 2003 3:24 pm

what pejone is trying to say, but as usual says it in a very cryptic way, is that you just read out the dir and delete the files. e.g.:

Code: Select all

function folder($dir) {
  $i=0;
  if($handle = opendir($dir)) {
    while(false !== ($file = readdir($handle))) {
      if($file != "." && $file != "..") {
        unlink($dir . $file);
      }
    }
    closedir($handle);
  }
}   

roadkillbunny
New php-forum User
New php-forum User
Posts: 9
Joined: Sat Mar 22, 2003 4:03 pm
Contact:

Sun Mar 23, 2003 6:21 pm

so this function clears a folder? THX
RoadkillBunny

Visit me at http://www.middleoftheroad.tk

roadkillbunny
New php-forum User
New php-forum User
Posts: 9
Joined: Sat Mar 22, 2003 4:03 pm
Contact:

Sun Mar 23, 2003 6:28 pm

Shouldn't there be only one = in false !== ($file = readdir($handle)) ??[/quote]
RoadkillBunny

Visit me at http://www.middleoftheroad.tk

Xerpher
New php-forum User
New php-forum User
Posts: 164
Joined: Tue Aug 27, 2002 8:25 pm
Location: Ontario, Canada
Contact:

Sun Mar 23, 2003 6:32 pm

No. == and === are different. one checks content, the second checks contents AND vartype I believe.
Terra Design, my business and sole / huge PHP project... a fully dynamic and adaptive site engine.

roadkillbunny
New php-forum User
New php-forum User
Posts: 9
Joined: Sat Mar 22, 2003 4:03 pm
Contact:

Sun Mar 23, 2003 7:30 pm

One more question.

How can I delete all the files that end in a specific string.
Do I add $file != *jpg (if I want to delete all jpg files) to where it checks . and ..?
RoadkillBunny

Visit me at http://www.middleoftheroad.tk

Xerpher
New php-forum User
New php-forum User
Posts: 164
Joined: Tue Aug 27, 2002 8:25 pm
Location: Ontario, Canada
Contact:

Sun Mar 23, 2003 7:56 pm

I use

substr($file, -3) != 'jpg'
Terra Design, my business and sole / huge PHP project... a fully dynamic and adaptive site engine.

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 7 guests