SitePoint Sponsor |
|
User Tag List
Results 1 to 6 of 6
Thread: Delete all files in folder.
-
May 9, 2005, 07:58 #1
- 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?!
-
May 9, 2005, 08:10 #2
- 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!
-
May 9, 2005, 08:13 #3
- 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.
-
May 9, 2005, 08:17 #4
- Join Date
- May 2005
- Location
- Holland!
- Posts
- 852
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by rassenvn
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);
?>
GaloBusiness as usual is off the menu folks, ...
-
May 9, 2005, 08:26 #5
- 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.
-
May 9, 2005, 08:29 #6
- Join Date
- May 2005
- Location
- Holland!
- Posts
- 852
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by jaswinder_rana
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....
GaloBusiness as usual is off the menu folks, ...
Bookmarks