...

View Full Version : mkdir & unlink question!



angst
09-09-2005, 07:48 PM
Hi,
I've build a scipr that generates directories and index pages for each dir
using mkdir:
mkdir($CatDirName, 0777);

I need to remake this dirs everytime a directory is added/removed or edited.

but when i run the script again I get this error:

Warning: mkdir() [function.mkdir]: File exists in C:\Program Files\xampp\htdocs\dating\admin\makedirs.php on line 20

if I try to use unlink, I get this error:

Warning: unlink
[function.unlink]: Permission denied in makedirs.php on line 18

how can I get around this? is there an option for mkdir & fopen($filename,"x+") to overwrite even if the directory or file already exists?

thanks in advance for your time!
-Ken

devinemke
09-09-2005, 08:05 PM
check to see if the directory exists using file_exists (http://www.php.net/file_exists)

angst
09-09-2005, 08:18 PM
ok,
But i still can't unlink a directory for some reason,,
any idea why? is there something wrong with my code??

unlink('/Program Files/xampp/htdocs/dating/Alternative_Dating/');


hmm,, just looking at that right now, maybe it doesn't like the space in program files?

-Ken

marek_mar
09-09-2005, 08:21 PM
For deleting folders there is rmdir() (http://www.php.net/rmdir)

angst
09-09-2005, 08:48 PM
oh great!
I found a nice little function on that page that someone built to
removed a directory and all it's contents.

in case anyone needs it:



function rmdirr($dir) {
if($objs = glob($dir."/*")){
foreach($objs as $obj) {
is_dir($obj)? rmdirr($obj) : unlink($obj);
}
}
rmdir($dir);
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum