Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

<cfdirectory> delete how do i get around . .. recursion problem ?

Status
Not open for further replies.

pinny

Programmer
Jan 27, 2001
4
GB
i want to delete a directory and all further dir's and content in directory tree. but when i get a list of directory contents it retrieves the . and .. standard in dir. structure, how do i loop through list and delete and ignore . and ..
driving me mad please help !!!!!!!
 
Hi Pinny,

There's no easy way to do this with the default CF tags unless you spend some time on a recursive function. I would suggest creating a custom tag called "deleteDir" which takes one parameter, the directory to delete. In this function, do a cfdirectory to see if the directory is empty. If it is, use the cfdirectory tag to delete it. If it's not empty, you then call "deleteDir" again (recursively) and pass it the full path of the subdirectory. The trick is that you have to make a copy of the directory listing before you make a recursive call. As I recall, using cfdirectory in a recursive fashion overwrites the directory listing so that it's not the same once the recursive call completes.

Let me know if you need further help,
GJ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top