View Full Version : mkdir & unlink question!

09-09-2005, 08:48 PM
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!

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

09-09-2005, 09:18 PM
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?


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

09-09-2005, 09: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);