FtpClient.DirectoryExists Method

System.Net.FtpClient

Collapse image Expand Image Copy image CopyHover image
Tests if the specified directory exists on the server. This method works by trying to change the working directory to the path specified. If it succeeds, the directory is changed back to the old working directory and true is returned. False is returned otherwise and since the CWD failed it is assumed the working directory is still the same.

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

Syntax

C#
public bool DirectoryExists(
	string path
)
Visual Basic
Public Function DirectoryExists ( 
	path As String
) As Boolean
Visual C++
public:
virtual bool DirectoryExists(
	String^ path
) sealed

Parameters

path
Type: System..::..String
The path of the directory

Return Value

Type: Boolean
True if it exists, false otherwise.

Implements

IFtpClient..::..DirectoryExists(String)

Examples

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

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

                if (conn.DirectoryExists("/full/or/relative/path")) {
                    // do something
                }


            }
        }
    }
}

See Also