f



Delete a directory and all its files and sub-directories?

Hi,

Does anyone know of, or have code that will delete a php directory and
all its sub directories and files.  "unlink" and "rmdir" don't do this.
 I'd prefer not to use "exec" with a system call but if that's the only
way, so be it.

I'm using PHP 4.4.4.

Thanks, - Dave

0
1/4/2007 9:31:18 PM
comp.lang.php 32646 articles. 0 followers. Post Follow

1 Replies
712 Views

Similar Articles

[PageSpeed] 35

laredotornado@gmail.com said:
> Does anyone know of, or have code that will delete a php directory and
> all its sub directories and files.  "unlink" and "rmdir" don't do this.
>  I'd prefer not to use "exec" with a system call but if that's the only
> way, so be it.
>
> I'm using PHP 4.4.4.
>
http://ie.php.net/rmdir
Read the first user comment on the page. The one with the function
recursiveRemoveDirectory() 

D.
-- 

0
Belial (118)
1/4/2007 10:36:24 PM
Reply:

Similar Artilces:

files, directories, files, directories
Hi folks, I've been trying to make a decision and it's driving me crazy. Is a directory a file or is a directory NOT a file but a node? Should I have A) public interface IFile { IFileName FileName; IContent GetContent(); } public interface IDirectory extends IFile { } or B) public interface INode { INodeName NodeName; } public interface IFile extends INode { IContent GetContent(); } public interface IDirectory extends INode { } Method A is nice cause IFile becomes the base "Node" type and you can use names like "IFileName" which sounds nice compared to "INodeName" and fits with the "FileSystem" moniker. A has the disadvantage that IDirectory has a GetContent() method which isn't bad but can be considered a bit weird. It probably wouldn't be too hard to make users think of everything as a file. Method B is nice cause IDirectory doesn't have GetContent() -- that honour belongs only to IFile. B is at a disadvantage when it comes to naming: everything becomes a "Node". INodeName sounds rude compared to IFileName. This method feels more "pure" cause you're specialising features completely. Do you reckon I can get away with Method A? It doesn't seem as pure unless you spend a long time convincing yourself that (for all intents and purposes) a file *is* a node (it's just got a different name) and a directory *is* a file. A penny for anyone's thought...

Delete all non *.jpg in a directory and sub directory
I would like to be able to delete all files from say /home/me/pics/ that aren't pictures, I have tried using find *.[\^Jj][\^Pp][\^Ee] [\^Gg] but it doesn't work. I would like to delete all files not matching *.jpg *.jpeg and be case insensitive. So *.JPEG or *.JPg does not get deleted. Thanks a lot. On Nov 19, 2:18 pm, Eliot <e...@hotmail.com> wrote: > I would like to be able to delete all files from say > /home/me/pics/ > that aren't pictures, I have tried using find *.[\^Jj][\^Pp][\^Ee] > [\^Gg] > but it doesn't work. > I would like to delete all f...

Find files in current directory excluding sub-directories
I use following two methods to find files in a directory but not its sub-directories on HP-UX B.11.11. $ find /home/jhl -type f ! -path './*/*' -name "*.c" $ find /home/jhl -type f -prune -name "*.c" But both present me with files in sub-directories. Can you teach me how to find files in current directory only? Thank you. lovecreatesbea...@gmail.com wrote: > I use following two methods to find files in a directory but not its > sub-directories on HP-UX B.11.11. > > $ find /home/jhl -type f ! -path './*/*' -name "*.c" > $ find /home/jhl -type f -prune -name "*.c" > > But both present me with files in sub-directories. > > Can you teach me how to find files in current directory only? Thank you. Hi, Try the following: $ find /home/jhl -path "/home/jhl/*" -prune -name "*.c" Jon Jon Fife wrote: > lovecreatesbea...@gmail.com wrote: > > I use following two methods to find files in a directory but not its > > sub-directories on HP-UX B.11.11. > > > > $ find /home/jhl -type f ! -path './*/*' -name "*.c" > > $ find /home/jhl -type f -prune -name "*.c" > > > > But both present me with files in sub-directories. > > > > Can you teach me how to find files in current directory only? Thank you. > > Try the following: > $ find /home/jhl -path "/home/jhl/*"...

Traversing Directories and Sub Directories and find tcl files
Hi all, I am looking for sample code to find the tcl files in directories and subdirectories. I tried to use -glob option of tcl to find all the directories and sub directories which contain tcl files. Can anyone help me in this regard? I want to know also is there a way that I can transfer the information printed in command console to a output file? On Nov 21, 4:58=A0pm, Pradeep <bubunia2000s...@gmail.com> wrote: > Hi all, > =A0 =A0 I am looking for sample code to find the tcl files in directories > and subdirectories. I tried to use -glob option of tcl to find all the > directories and sub directories which contain tcl files. Can anyone > help me in this regard? I want to know also is there a way that I can > transfer the information printed in command console to a output file? something like below should work: proc list_files {start} { foreach file [glob -nocomplain [file join $start *]] { if {[file extension $file] eq ".tcl"} { puts $file } if [file isdirectory $file] { list_files $file } } } list_files {/path/to/directory} about redirect script output to file read this http://groups.google.com/group/comp.lang.tcl/browse_thread/thread/22331539a= 0d8e920/ I hope this help you At 2008-11-21 05:58AM, "Pradeep" wrote: > Hi all, > I am looking for sample code to find the tcl files in directories > and subdirectories. I tried to use -glob option of tcl to find all the > directories...

Delete certain files in sub directories
In vb 6, I am trying to write a simple app that will run and delete files that are older than 10 days in a specific directory. No problem so far. Now, it has to go through every subdirectory below my specified directory. Thankfully, they only go one layer deep. Any ideas would be greatly appreciated, samples would be even better. Can you post the code you used? Madhivanan ...

Delete files in directoy and sub-directories
Hi everybody! Is there an easy line command to delete all file (let say the ones with the ..txt extension) present in a directory and its sub-directories without deleting the directories. Thanks a lot for your help. Jerome J�r�me VUIBERT typed (on Wed, Nov 26, 2003 at 06:06:12PM +0100): | Is there an easy line command to delete all file (let say the ones with the | .txt extension) present in a directory and its sub-directories without | deleting the directories. find /the/directory/you/want -type f ! -name "*.txt" | xargs rm -- JP Jean-Pierre Radley wrote: > Jirtme VUI...

Delete multiple files within sub directories?
Is there a way to delete multiple files using wildcards within the current and sub directories? For example, if I want to get rid of all files of the extension *.jpg, is there a way to delete these files from the subdirectories within one command line? Or do I need to go into each subdirectory and type "del *.jpg"? On 15 Mar 2007 15:58:20 -0700, "Jack" <mr_nice_1973@yahoo.com> wrote: >Is there a way to delete multiple files using wildcards within the >current and sub directories? For example, if I want to get rid of all >files of the extension *....

Getting all directories/files from current directory and using -d flag for the directories
Hi guys/gals, I'm pretty new to Perl, so please keep that in mind. :) It looks like File::Find goes through all the subdirectories of the current directory, which isn't what I want. I just want all the contents of the current directory. On doing some research, many people have recommended doing something like the following: ----------- $home_dir = ''; #changed to protect the innocent :) opendir(DIR,$home_dir) or die "Can't open the current directory: $home_dir $!\n"; # read file/directory names in that directory into @names @names = readdir(DIR) or die "...

delete-file & probe-file on directories
should delete-file and probe-file work on directories? e.g. suppose we have a file "foo" and a subdirectory "bar/". what should (probe-file "foo") (probe-file "foo/") (probe-file "bar") (probe-file "bar/") return? one could argue that the first two invocations should return the same as (truename "foo") and the last two the same as (truename "bar/"). one can also argue that the 2nd and 3rd should return nil - especially if it is possible to have same named files and subdirectories (are there filesystems where fi...

Extracting Directories and Sub Directories and Counting
#!/usr/bin/perl use strict; print "\n"; my %HoA; for ( `dir /b/s` ) { push @{ $HoA{$1} }, $2 if /(.+)\\(\w+)\.\d+\.\w+$/; } for my $dir ( sort keys %HoA ) { print join ( "\n", $dir ), "\n\n"; my @basenames = @{ $HoA{$dir} }; my %count; for my $frames ( @basenames ) { $count{$frames} += 1; } for ( sort keys %count ) { printf "%30s\t%04d\n", $_, $count{$_}; } print "\n"; } gives me: file_base_name file_count in two columns. How would I add additional columns like: file_base_name file_cou...

Deleting a directory with all its files?
Hello, What is the best method to recursively delete a directories with all its contents i.e. files and subdirectories? regards, Karam __________________________________ Do you Yahoo!? New and Improved Yahoo! Mail - 100MB free storage! http://promotions.yahoo.com/new_mail --------------------------------------------------------------------- To unsubscribe, e-mail: wx-users-unsubscribe@lists.wxwidgets.org For additional commands, e-mail: wx-users-help@lists.wxwidgets.org On Mon, 9 Aug 2004 07:58:51 -0700 (PDT), you wrote: >Hello, > >What is the be...

How do I delete files from a directory?
Hi all: I would like to find out how to write a small program that deletes files. I want to be able to delete all files from a known directory (i.e. cookies, temp files, etc.) regardless of type and name, "or" may be by extension. This way I could have it run on start up and I will have my computer free of junk every time I reboot. What should I use? Please advise. In message <ifqdnc60VrqHQH_d4p2dnA@comcast.com>, Sonoman <nospam@microsoft.com> writes >Hi all: >I would like to find out how to write a small program that deletes files. I >want to be able to dele...

Delete files in a directory
Hello, this is my first post here, so first i would like to thanks all the people who works for this site. Well, i'm trying to set up a little script that should delete all the files in a given drectory; the system should work like this: -I have the name and the path of file = "/Users.....file1" -from file, i should get the directory (I've used File.dirname(file)) -from that directory, i should delete all files and sub directories except from the given file (in this case, file1) I'm making confusion when i try to iterare on the files and irectory in that folder, and i&...

How to delete all files in a directory?
Hello, How can I delete all files in the directory /usr/me/data ? I tried file delete -force /usr/me/data/* but that did not work. Thanks in advance Nadeem foreach file [glob -nocomplain -directory /usr/me/data *] { file delete -force $file } In 8.5, you could also do file delete -force {*}[glob -nocomplain -directory /usr/me/data *] Another option, at least on Windows (and I assume elsewhere): file delete -force c:/usr/me/data which deletes not only the contents of the directory, but also the directory itself. (If needed, you could then recreate the directory using [file mkdir /usr/me/data].) khannu@gmail.com wrote: > I tried > file delete -force /usr/me/data/* > but that did not work. Aric's message says how to do what you want, but you should be aware of *why* this all matters. Tcl, unlike bash, does not do glob expansion of any filename patterns unless explicitly asked to. This is a good thing, since it means that Tcl scripts aren't derailed by unusual characters (unlike virtually every bash script ever written!) However, it also means that when you want globbing you need to do a bit more work and do the iteration yourself. Of course, if you're really after squelching the whole directory, you should just [file delete -force /usr/me/data] but only do that if you do not care to keep the directory at all. Yes, delete/recreate can work, but it's easy to lose important aspects like directory attributes if you're no...

Script to move files with one occurence of a string to one directory, and other files to another directory?
I could use a script for the bash shell to look through a group of files (s= elected from one directory by a wildcard expression) and move any of those = files with exactly one occurrence of the string Path: to a different direct= ory, usually a subdirectory of the first directory. The rest of the files = selected by the wildcard expression are move to a third directory, also usu= ally a subdirectory of the first directory. I'm currently doing this manua= lly, but with grep commands to count the number of occurrences. NOT homework - I'm retired. Actually using Cygwin (an em...

Files, directories and imports
Hello, group. I can only read files and import modules that are in the same directory as the one my script is. Here is a test script (path.py): import os import uno # some module I wrote print list(os.walk('~/hacking/python')) f = open('~/read/foo.txt') print f.read() And here is the output: Traceback (most recent call last): File "path.py", line 2, in <module> import uno ImportError: No module named uno If I comment that import, the output becomes this: [] Traceback (most recent call last): File "path.py", line 4, in <modu...

Find number of sub directories within a directory
Hi, Objective of program is: get total file size in a folder, get total recursive file size (including all subdirectories and the directory itself) and get number of sub directories in each directory. Example--- Want output to be something like this, I can format the output don't worry about that, just need to get the information into the hash or whereever. Dir File Size Recursive File Size # of Sub dirs c:\blah 100kb 400kb 4 c:\blah\f1 50kb 50kb 0 c:\blah\f2 50kb 50kb 0 c:...

listing sub directories of a directory using hla
Hi, i need to write a code in HLA, a part of which involves listing the contents of a directory ( i.e. its subdirectories and filecontents) . Any help in this regard will be appreciated. with best regards Prateek Gupta spamtrap@crayne.org wrote: > >i need to write a code in HLA, a part of which involves listing the >contents of a directory ( i.e. its subdirectories and filecontents) . >Any help in this regard will be appreciated. The key piece of information you did not tell us is what operating system you are targetting. The technique is VERY different for DOS, Win32, and Linu...

Konqueror saves file .directory in every directory
Konqueror saves file called ".directory" in every directory where I change some view properties of this directory, e.g. when clicking the "Detailed view" icon. I can see this behaviour on only one my machine/account with KDE, while it is working fine elsewhere. How can I disable this nasty file creation? BTW, someone knows how to use a web search engine (google, yahoo, ...) to search for ".directory"? They always strip the leading "." and thus giving out millions of useless results. Thanks, P.M. Quoth Petr Mikulik : > Konqueror saves file called ".directory" in every directory where I > change some view properties of this directory, e.g. when clicking the > "Detailed view" icon. I can see this behaviour on only one my > machine/account with KDE, while it is working fine elsewhere. How can > I disable this nasty file creation? Don't change any nasty properties and you won't create this nasty file. > BTW, someone knows how to use a web search engine (google, yahoo, ...) > to search for ".directory"? They always strip the leading "." and thus > giving out millions of useless results. Did you mean to ask, "Does someone know how to use a web search engine?" The answer is... yes, someone does. It's just not you. For instance, I would never start a search for "dumb questions about my operating system GUI" with the lone term "dum...

Re: Finding directory file of current directory
From: "R Boyd" <bob@hax.com> > Here's a command procedure I wrote years ago to handle the issue: [...] > See if that solves your problem. It probably will unless it encounters a contrary ODS5 extended file name: ALP $ show default LDA1:[o5_test.TEST2.a^[b^]c] ALP $ @ [--]uponedir.com PREV_DIR_LEV = "LDA1:[o5_test.TEST2]" CUR_DIR_SPEC = "LDA1:[o5_test.TEST2]a^[b^c].DIR" ALP $ dir [-]a*.dir Directory LDA1:[o5_test.TEST2] a^[b^]c.DIR;1 Total of 1 file. Everything's complicated. (And getting more so all the time.) From: JONE...

List files from directory not in apache web directory
Hello everyone, is it possible to list files from directory other than in apache web directory? my web folder is placed on c:/ and i put my files in windows directory "d:/files/images/". I want those files to be able to view in client browser. when i tested using server computer it succeed. but from client computer i got nothing. I checked the html sources and the files is directly loaded from "d:/ files/images/file_name.jpg" and then i found out why computer client could not load that files. is there any other way to make it happened ? thank you guys for any kind of help. best regards. On Apr 4, 12:17 pm, froditus <frodi...@gmail.com> wrote: > Hello everyone, > > is it possible to list files from directory other than in apache web > directory? > my web folder is placed on c:/ and i put my files in windows directory > "d:/files/images/". > I want those files to be able to view in client browser. when i tested > using server computer it succeed. but from client computer i got > nothing. > I checked the html sources and the files is directly loaded from "d:/ > files/images/file_name.jpg" and then i found out why computer client > could not load that files. > > is there any other way to make it happened ? > > thank you guys for any kind of help. > > best regards. It will not be accessible from the client computer because apache cannot interpret the path. You should build a p...

Recursive delete of directory
I'm trying to remove a directory and all its contents from within a script. I wrote a recursive function to take care of it, but when I run it I get random "Directory not empty" error messages. I dropped some code in to echo out the name of the file that's about to be rmdir()ed or unoink()ed (depending if it's a file or a directory) to see if it was choking on a particular subdirectory, but doing that causes all the error messages to stop appearing! It looks to me as if at some stages of the script the delete commands are being issued too rapidly and the result is that an attempt to delete a parent is made before its children have all been deleted. The code I added to echo out the directory name first probably introduces just enough of a delay for this problem to go away. Obviously just doing something in the function to cause a delay isn't a good solution, is there a better way of handling this problem? I'm running PHP 5 on a Windows development machine through Apache. Directory listings are being retrieved from a database. Gordon wrote: > I'm trying to remove a directory and all its contents from within a > script. I wrote a recursive function to take care of it, but when I > run it I get random "Directory not empty" error messages. > > I dropped some code in to echo out the name of the file that's about > to be rmdir()ed or unoink()ed (depending if it's a file or a > directory) to see if it was...

Using File::Find to delete files and directories older than 30 days
I am a Perl beginner and I hve writen this script to remove files older than 30 days, it works well EXCEPT that it leave the empty directories behind, can anyone help me look for empty directories and remove them as well? TIA, Steve #! Perl -w use Strict; use File::Find; $tempdir = "D:\\shared dirs\\temp Public"; find(\&Wanted, $tempdir); sub Wanted { #Do not scan Purchasing or Budget return $File::Find::prune = 1 if $_ eq "Purchasing - Do Not Remove"; return $File::Find::prune = 1 if $_ eq "BUDGET"; # only on files older than 30 days if ( ( -M $_ ) > 30 ) { @args = ("del", "/F", "/Q", "$_"); system @args; } } SteveO <stevehobrien@hotmail.com> wrote: > I am a Perl beginner Have you seen the Posting Guidelines that are posted here frequently? > to remove files older > than 30 days, it works well EXCEPT that it leave the empty directories > behind, > #! Perl -w > use Strict; > use File::Find; > $tempdir = "D:\\shared dirs\\temp Public"; That should fail to compile under strictures, you did not declare $tempdir. use strict; Case matters. use warnings; is better than the -w switch If you use single quotes, then you won't have backslash the backslashes: my $tempdir = 'D:\shared dirs\temp Public'; Or, better yet, use sensible slashes instead of silly slashes: my $tempdir = 'D:/shared dirs/temp Public'; &g...

List of directories with a directory
I have a directory with 200 sub directories in it. How do I create a list of the sub directory names? I know how create a list of all the files in a directory: opendir(DIR, $dirname) or die "can't open $dirname: $!"; while (defined($file = readdir(DIR))) { next if($file =~ m/^\./); next if($file eq ""); push (@filenames, $file); } closedir(DIR); but how do I do it for the directories within a directory Al Moodie. On Tue, 29 Jan 2008 19:45:50 -0500, Al Moodie <nospam@nospam.com> wrote: >I have a directory with 200 sub directories in it. How do I create ...

Web resources about - Delete a directory and all its files and sub-directories? - comp.lang.php

Google Now Showing Sitelinks for Some Sub-Directories
As Googler, Matt Cutts Twittered, he now has Sitelinks under his domain for a search on [matt cutts]. Why did it take Matt over two years to ...

Resources last updated: 3/23/2016 9:12:09 PM