FtpClient.DeleteDirectory Method (String, Boolean, FtpListOption)

System.Net.FtpClient

Collapse image Expand Image Copy image CopyHover image
Deletes the specified directory on the server

Namespace: System.Net.FtpClient
Assembly: System.Net.FtpClient (in System.Net.FtpClient.dll) Version: 1.0.5064.17461

Syntax

C#
public void DeleteDirectory(
	string path,
	bool force,
	FtpListOption options
)
Visual Basic
Public Sub DeleteDirectory ( 
	path As String,
	force As Boolean,
	options As FtpListOption
)
Visual C++
public:
virtual void DeleteDirectory(
	String^ path, 
	bool force, 
	FtpListOption options
) sealed

Parameters

path
Type: System..::..String
The full or relative path of the directory to delete
force
Type: System..::..Boolean
If the directory is not empty, remove its contents
options
Type: System.Net.FtpClient..::..FtpListOption
FtpListOptions for controlling how the directory contents are retrieved with the force option is true. If you experience problems the file listing can be fine tuned through this parameter.

Implements

IFtpClient..::..DeleteDirectory(String, Boolean, FtpListOption)

Examples

C#  Copy imageCopy
using System;
using System.Net;
using System.Net.FtpClient;

namespace Examples {
    static class DeleteDirectoryExample {
        public static void DeleteDirectory() {
            using (FtpClient conn = new FtpClient()) {
                conn.Host = "localhost";
                conn.Credentials = new NetworkCredential("ftptest", "ftptest");

                // Remove the directory and all objects beneath it. The last parameter
                // forces System.Net.FtpClient to use LIST -a for getting a list of objects
                // beneath the specified directory.
                conn.DeleteDirectory("/path/to/directory", true, 
                    FtpListOption.AllFiles | FtpListOption.ForceList);
            }
        }
    }
}

See Also