Forum Moderators: coopster

Message Too Old, No Replies

delete complete folders with unlink or rmdir

delete complete folders with unlink or rmdir

         

phparion

7:34 pm on Mar 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



hi,

i have a directory with structure like

project
- images
- include
- classes
- deletefolder.php

i want to delete three folders from project directory which is my main site folder. the page that will take action also resides in project directory. i was using command like

PHP Code:
if(condition) {
unlink("/images");
unlink("images");
//it was not working so i tried
unlink("../images");
}

but both are not working and gives error

Code:
no such directory found

please guide me how can i delete complete folders depending on condition in page.

i also tried rmdir() but it deletes empty folders and i want to delete folder full with php pages.

thanks in advance

jatar_k

7:45 pm on Mar 8, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



take a look through the user comments on this page
[php.net...]

it looks like there might be a function in there for this.

from the same page

The directory must be empty, and the relevant permissions must permit this

there are commands to do this from the command line but not with rmdir, rm -rf dirname works but rm -rf is a very dangerous and greedy little function.

You just need to loop through the files in the selected dir and unlink each one, then remove the directory afterwards.

phparion

8:17 am on Mar 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Warning: Unlink failed (No such file or directory) in c:\apache\htdocs\beta opm\include\info.php on line 14
localhost

my info.php page is in main Project folder and INCLUDE folder is a sub folder in project like i described in my first post but i dont know why its giving path in warning like

Code:
c:\apache\htdocs\beta opm\include\info.php
coz i dont have info.php in include folder.

any idea?

phparion

5:38 pm on Mar 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



anyone?

bcolflesh

5:41 pm on Mar 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try using the fully qualified path in your unlink statement, ex:

c:\apache\htdocs\beta opm\myprojectname\images\