User (Old forums)MemberNovember 11, 2003 at 10:21 amPost count: 23064
Is there any way to delete muliple files based on my mask.
Imported from legacy forums. Posted by James (had 5811 views)User (Old forums)MemberNovember 11, 2003 at 11:26 amPost count: 23064
Unfortunately, the library does not offer this shortcut. You need to call GetFolderContents with the file mask, walk through each items and delete them one by one. The FTP protocol does not offer that functionality anyway, so that’s exactly what the library would have done underneath a “DeleteFiles” method.
Imported from legacy forums. Posted by Martin (had 337 views)User (Old forums)MemberFebruary 29, 2004 at 6:39 pmPost count: 23064
Can I expand this question?
How would/should this work for deleting a folder containing a folder. Would I call “GetFolderContents” on the contained folder?
Imported from legacy forums. Posted by tgulrud (had 405 views)User (Old forums)MemberMarch 1, 2004 at 9:20 amPost count: 23064
Yes, you would need to build yourself a recursive function that gets the content of each folder, deletes each file, goes into subfolders and calls itself recursively, then goes back one folder and deletes the “now-empty” folder.
It’s too bad Xceed FTP ActiveX does not offer a “recursive RemoveFolder”. The .NET version does. I’ll take good note of such a feature.
If I have some spare time today, I’ll post an implementation of a “RemoveFolderRecursive” function. In what language are you developping?
Imported from legacy forums. Posted by Martin (had 257 views)User (Old forums)MemberMarch 1, 2004 at 8:04 pmPost count: 23064
Thanks much that would be great. VB 6.0.
Imported from legacy forums. Posted by tgulrud (had 413 views)User (Old forums)MemberMarch 2, 2004 at 10:26 amPost count: 23064
Here is a VB6 implementation of a RemoveFolderRecursive function. I did not put any error checking into this.
Public Sub RemoveFolderRecursive(ByVal xFtp As XceedFtp, ByVal sFolder As String)
‘ The steps are as follows:
‘ a) Get the current working folder so we can get back into it.
‘ We can’t use ChangeToParentFolder, as links could move us in
‘ a completely different path.
‘ b) Change into sFolder
‘ c) Remove all files
‘ d) Try to delete all links
‘ d) Call ourself recursively for each folder or remaining link
‘ (except for . and ..)
‘ e) Get back to original working folder
‘ f) Delete sFolder.
Dim sWorkingFolder As String
sWorkingFolder = xFtp.CurrentFolder
Dim xItems As XceedFtpFolderItems, xItem As XceedFtpFolderItem
Dim xFolders As New Collection
Set xItems = xFtp.GetFolderContents(“”, fcfCollection)
For Each xItem In xItems
Select Case xItem.ItemType
On Error Resume Next
If Err.Number <> 0 Then
On Error GoTo 0
If (xItem.ItemName <> “.”) And (xItem.ItemName <> “..”) Then
For Each xItem In xFolders
Call RemoveFolderRecursive(xFtp, xItem.ItemName)
Set xFolders = Nothing
Imported from legacy forums. Posted by Martin (had 5815 views)
- You must be logged in to reply to this topic.