UNLINK MULTIPLE

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

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

UNLINK MULTIPLE

Postby roadkillbunny » Sat Mar 22, 2003 8:41 pm

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

User avatar
Oleg Butuzov
Last Samuray
Last Samuray
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

Postby Oleg Butuzov » 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:

Postby roadkillbunny » 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?

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

Postby *JaH* » 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:

Postby roadkillbunny » Sun Mar 23, 2003 6:21 pm

so this function clears a folder? THX

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

Postby roadkillbunny » Sun Mar 23, 2003 6:28 pm

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

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

Postby Xerpher » Sun Mar 23, 2003 6:32 pm

No. == and === are different. one checks content, the second checks contents AND vartype I believe.

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

Postby roadkillbunny » 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 ..?

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

Postby Xerpher » Sun Mar 23, 2003 7:56 pm

I use

substr($file, -3) != 'jpg'


Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 2 guests