Home Forums ActiveX components Xceed FTP for ActiveX Delete multiple files ??

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #42638 |

    Is there any way to delete muliple files based on my mask.

    Eg. xfTP.DeleteFile(“*.*”)

    Thanks

    Imported from legacy forums. Posted by James (had 5811 views)

    User (Old forums)
    Member
    Post count: 23064

    Hello James.

    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)
    Member
    Post 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?

    Thanks,
    -Tom

    Imported from legacy forums. Posted by tgulrud (had 405 views)

    User (Old forums)
    Member
    Post count: 23064

    Hello Tom.

    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)
    Member
    Post count: 23064

    Thanks much that would be great. VB 6.0.

    Imported from legacy forums. Posted by tgulrud (had 413 views)

    User (Old forums)
    Member
    Post count: 23064

    Hello Tom.

    Here is a VB6 implementation of a RemoveFolderRecursive function. I did not put any error checking into this.

    <code>
    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

    Call xFtp.ChangeCurrentFolder(sFolder)

    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
    Case fitFile
    Call xFtp.DeleteFile(xItem.ItemName)
    Case fitLink
    On Error Resume Next
    Call xFtp.DeleteFile(xItem.ItemName)

    If Err.Number <> 0 Then
    Call xFolders.Add(xItem)
    End If

    On Error GoTo 0
    Case fitFolder
    If (xItem.ItemName <> “.”) And (xItem.ItemName <> “..”) Then
    Call xFolders.Add(xItem)
    End If
    End Select
    Next

    For Each xItem In xFolders
    Call RemoveFolderRecursive(xFtp, xItem.ItemName)
    Next

    Set xFolders = Nothing

    Call xFtp.ChangeCurrentFolder(sWorkingFolder)
    Call xFtp.RemoveFolder(sFolder)
    End Sub
    </code>

    Imported from legacy forums. Posted by Martin (had 5815 views)

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.