SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    US
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Delete all files in folder.

    i'm trying to write a delete func.
    but i duno, how can i delete all file with $name="aaa"; and all extension.....
    anybody can show me this script?!

  2. #2
    orange pips! orange pips!
    Join Date
    Oct 2001
    Location
    Its all about location
    Posts
    652
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The first user comment here on php.net details a function to recursively delete all directories within a specified directory.

    Hope this helps!

  3. #3
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    would you clear, do you want to remove certain files, with in a certain directory
    or
    the whole directory
    or files in a directory and within further directories.
    ---------------------------
    Errors = Improved Programming.
    My Site

  4. #4
    SitePoint Guru Galo's Avatar
    Join Date
    May 2005
    Location
    Holland!
    Posts
    852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by rassenvn
    i'm trying to write a delete func.
    but i duno, how can i delete all file with $name="aaa"; and all extension.....
    anybody can show me this script?!
    Hey there, since im new to this boars i can't realy comment ojn the way you posted this message, it's like nobody reads stuff anymore these days.

    Anyway i'll try and help ya anyway if you will try to look up on this sort of information on php.net and google BEFORE posting such a question, but then again who am i to tell you that

    This is what you want....

    PHP Code:
    <?php

        
    if(!isset($_ENV['WINDIR'])){
            
    $userfile str_replace("/""\\"$file);
            
    exec("del $file");
            if(
    file_exists("$file")){
                die(
    "cant delete file!");
            }elseif(!@
    unlink($file)){
                die(
    "Cant delete file!");
            }
        }
        
        
    $default_dir "homes/james";

        function 
    traverse_dir($dir){
            echo 
    "Traversing directory...";
            
    chdir($dir);
            if(!(
    $dp opendir($dir))){
                die(
    "Can't open directory");
            }
            
            while(
    $file readdir($dp)){
                if(
    is_dir($file)){
                    if(
    $file != '.' && $fila != '..'){
                        echo 
    "/$file<br>";
                        
    traverse_dir("$dir/$file");
                        
    chdir($dir);
                    }
                }else{
                    echo 
    "$file<br>";
                }
                
    closedir($dp);
            }
        }
        
        
    traverse_dir($default_dir);

    ?>
    hhope this helps,
    Galo
    Business as usual is off the menu folks, ...

  5. #5
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Galo,
    No Offense but,
    i think that was a harsh comment to make. everybody reads and try to help as mcuh as they can and they ask questions just to help the person more effectively.

    and, yes suggestion for searching on Google is good, but the way of suggestion wasn't good. Please, try to be more polite for everybody. everybody might not be as good as you are.

    and, its good you posted some code to help the person and that's what all people do here.
    ---------------------------
    Errors = Improved Programming.
    My Site

  6. #6
    SitePoint Guru Galo's Avatar
    Join Date
    May 2005
    Location
    Holland!
    Posts
    852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jaswinder_rana
    Hi Galo,
    No Offense but,
    i think that was a harsh comment to make. everybody reads and try to help as mcuh as they can and they ask questions just to help the person more effectively.

    and, yes suggestion for searching on Google is good, but the way of suggestion wasn't good. Please, try to be more polite for everybody. everybody might not be as good as you are.

    and, its good you posted some code to help the person and that's what all people do here.

    sorry i was not aware of the fact that my post was offending, i appologise.
    The reason is that im not english, im dutch so my grammar is not perfect.
    No hard feelings....

    Galo
    Business as usual is off the menu folks, ...


Bookmarks

Posting Permissions

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