Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts

    Question mkdir & unlink question!

    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

  • #2
    Regular Coder devinemke's Avatar
    Join Date
    Dec 2004
    Location
    NYC
    Posts
    443
    Thanks
    0
    Thanked 12 Times in 11 Posts
    check to see if the directory exists using file_exists

  • #3
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    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

  • #4
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    For deleting folders there is rmdir()
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #5
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    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:

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



  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •