FtpClient.DeleteDirectory Method (String, Boolean)

System.Net.FtpClient

Collapse image Expand Image Copy image CopyHover image
Delets 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
)
Visual Basic
Public Sub DeleteDirectory ( 
	path As String,
	force As Boolean
)
Visual C++
public:
virtual void DeleteDirectory(
	String^ path, 
	bool force
) 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

Implements

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

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