Home » How to Check if a Directory Exists in CMD

How to Check if a Directory Exists in CMD

You can use the if exists command in Command Prompt (CMD) to check if a directory exists:

if exist "directory_path" (
    echo Directory exists.
) else (
    echo Directory does not exist.
)

In this example, if exist command followed by the directory path check if the specified directory exists and display a message accordingly.

The following example shows how to use this syntax in practice.

Example: How to Check if a Directory Exists in CMD

Suppose that we want to check if the following directory exists:

C:\Users\admin\Documents\cmd_script

We can type the following command to check if the directory exists:

if exist "C:\Users\admin\Documents\cmd_script" (
    echo Directory exists.
) else (
    echo Directory does not exist.
)

Output: 👇️

Directory exists.

We can see that the command checks if C:\Users\admin\Documents\cmd_script exists and displays the appropriate message.

Conclusion

You can use the if exist command followed by the path to check if any directory exists on your system.

You can find more topics about Active Directory tools and PowerShell basics on the ActiveDirectoryTools home page.