Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

recursive deletion

Posted on 2003-11-20
5
Medium Priority
?
391 Views
Last Modified: 2010-05-03
I need to create a function that will recurse through a folder structure and delete all the files in them. This will then allow me to delete the folders when empty. I am trying to delete a folder off an ftp site but this can only be done if the folder is empty. I do not know how many subfolders there may be in ths folder or how many files in the folder.

All I know is the current path i am on and the contents of the directories.

I can delete all the files in 1 go but to delete a directory it has to be empty.

e.g i an use the kill *.* command to delete the files and the RMdir command to delete the folders but this has to be empty. I cannot use the fsscipt commands as it is on a remote site.

Thanks in advance if you can help Simon
0
Comment
Question by:scg198
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 7

Accepted Solution

by:
wsteegmans earned 400 total points
ID: 9790196
A real DelTree!

Public Sub DelTree(sFolder As String)
    Dim sCurrFile As String
   
    sCurrFile = Dir(sFolder & "\*.*", vbDirectory)
   
    ' Loop all files/directories ...
    Do While Len(sCurrFile) > 0
       
        ' Skip the directories . and ..
        If sCurrFile <> "." And sCurrFile <> ".." Then
       
            ' If it's a folder, call Deltree Recursively
            If (GetAttr(sFolder & "\" & sCurrFile) And vbDirectory) = _
                vbDirectory Then
               
                Call DelTree(sFolder & "\" & sCurrFile)
               
                ' Next
                sCurrFile = Dir(sFolder & "\*.*", vbDirectory)
            Else
           
                ' It's a file, so delete ...
                Kill sFolder & "\" & sCurrFile
                sCurrFile = Dir
            End If
           
        ' If it's . or .., just next ...
        Else
            sCurrFile = Dir
        End If
       
    Loop
   
    ' Remove the folder itselves!
    RmDir sFolder
   
End Sub
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 9790646
Thanks a great function wsteegmans, but scg198 is looking for a recursive delete for a client logged onto an FTP server.

"I am trying to delete a folder off an ftp site ..."

Idle_Mind
0
 
LVL 7

Expert Comment

by:wsteegmans
ID: 9790890
Idle_Mind ,

You dropped your question in the Visual Basic Group ... That's why ...
Could maybe dropped it ... under WebServer or something like that

Anyways ... Did you try to make the connection via your Windows Explorer, or by the Internet Explorer ...
Just type ftp://xxx.xxx.xxx.xxx, connect with login and password, and your directory-structure appears in your Explorer ...

There, just click on a your Folder and Press-Delete ... Everything is deleted: Files and Subfolders ...

Success!
0
 
LVL 7

Expert Comment

by:wsteegmans
ID: 9790900
scg198,

Sorry, took the wrong name ... :-(

The same ;-)

You dropped your question in the Visual Basic Group ... That's why ...
Could maybe dropped it ... under WebServer or something like that

Anyways ... Did you try to make the connection via your Windows Explorer, or by the Internet Explorer ...
Just type ftp://xxx.xxx.xxx.xxx, connect with login and password, and your directory-structure appears in your Explorer ...

There, just click on a your Folder and Press-Delete ... Everything is deleted: Files and Subfolders ...

Success!

0
 

Author Comment

by:scg198
ID: 9795657
Even though you did it for the local drive wsteegmans you answered one question that i had not tried calling the same function over and over again which is the answer so you can have the points
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question