Home » How to Search for a Directory in CMD

How to Search for a Directory in CMD

You can use the dir /S /B in Command Prompt (CMD) to search for a directory:

dir /S /B "directory_path\directory_name"

In this example, the dir command will search for the specified directory name within the given path and its subdirectories.

Note: The /S flag specifies to search all subdirectories, and the /B flag specifies to use directory names.

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

Example: How to Search for a Directory in CMD

Suppose that we want to search for a directory named cmd_script in the following path:

C:\Users\admin\Documents

We can type the following command to search for the directory:

dir /S /B "C:\Users\admin\Documents\cmd_script"

Output: 👇️

CMD - Search for a directory
CMD – Search for a directory

We can see that the command searches for the cmd_script folder within C:\Users\admin\Documents and its subdirectories, displaying the full path of any matching directories.

Note: You can use the dir command followed by the path and the directory name to search for any directory on your system.

Conclusion

I hope the above article on using the dir command to search for a directory in CMD.

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