Back to product page

DeleteFiles method


Delete multiple files in a sequence, recursive.

Type

Void

Syntax

  • C#
  • VB.NET
public Void DeleteFiles();

public Void DeleteFiles(String RemotePath);
The DeleteFiles(RemotePath) syntax has these parts:
RemotePathHolds full path on the server from where files/folders are deleted.

public Void DeleteFiles(String RemotePath, Int32 MaxLevel);
The DeleteFiles(RemotePath,MaxLevel) syntax has these parts:
RemotePathHolds full path on the server from where files/folders are deleted.
MaxLevelSpecifies maximum number of subdirectory levels to delete. 0 for unlimited.

public Sub DeleteFiles()

public Sub DeleteFiles(ByVal RemotePath As String)
The DeleteFiles(RemotePath) syntax has these parts:
RemotePathHolds full path on the server from where files/folders are deleted.

public Sub DeleteFiles(ByVal RemotePath As String, ByVal MaxLevel As Int32)
The DeleteFiles(RemotePath,MaxLevel) syntax has these parts:
RemotePathHolds full path on the server from where files/folders are deleted.
MaxLevelSpecifies maximum number of subdirectory levels to delete. 0 for unlimited.

Remarks

This method will try to delete complete directory structure on the server. You need to specify RemotePath that determines location from where files and directories are deleted.

wodFtpDLX.NET will go up to MaxLevel deep into recursion. Default value is 5 - meaning up to 5 subdirectory levels will be deleted. You can specify any value for MaxLevel. If you specify 0, that means that no restriction exists for recursion depth - this is dangerous setting that could cause infinite loops to be created if remote system has symbolic links pointing back to parent folders on remote system!

Before each item is deleted, LoopItem event will be fired, specifying remote file/folder name (including full path), type of the item (file/folder/symbolic link) and will allow you to Args.Skip the item so it is not deleted at all. Make sure your logic for setting Args.Skip = True is correct - if you skip deletion of the file and then try to delete it's parent directory, more errors can occur. Since DeleteFiles does not support wildcards (for example, you cannot specify "*.TXT" in DeleteFiles call), LoopItem event is a place to determine if certain item matches your wildcard expression (if you have any), so you can skip files that doesn't match your criteria.

If an errors occurs during deletion, LoopError event is fired holding in Args.Error error number and error description of the error. If you leave Args.Error value in LoopError event as is - DeleteFiles operation will be aborted. If you change Args.Error value in LoopError event to 0, then DeleteFiles operation will continue (ignoring the error) normally.

Please note that using DeleteFiles in blocking environment where events are not available is almost impossible to use - simply because first error that occurs may abort the operation, and there is no way to ignore the error (since you don't have access to LoopError event).

Do not forget that RemotePath should always specify full absolute path (i.e. /home/joe/something) instead of relative path (i.e. joe/something).

Platforms

Windows