You can use the following syntax in Command Prompt (CMD) to search for a directory by name and list all files within it:
for /D %G in ("directory_path\directory_name_pattern") do dir /S /B "%G\*"
In this example, it will search for directories within the given path that match the specified pattern and list all files within them.
Note: The /S flag specifies including all subdirectories, and the /B flag specifies using bare format (just the file names).
The following example shows how to use this syntax in practice.
Example: Search for a Directory and Find Files in CMD
Suppose that we want to search for directories that start with temp_ within the following path and list all files within them:
C:\Users\admin\Documents\cmd_script
We can type the following command to search for the directories and list the files:
for /D %G in ("C:\Users\admin\Documents\cmd_script\temp_*") do dir /S /B "%G\*"
Output: 👇️
We can see that the command searches for directories starting with temp_ within C:\Users\admin\Documents\cmd_script and lists all files within them.
Note: You can use the for and dir commands followed by the path and the name pattern to search for directories and list files on your system. Adjust the directory name pattern as needed.
Conclusion
I hope the above article on searching for directories and files in CMD is helpful to you.
You can find more topics about Active Directory tools and PowerShell basics on the ActiveDirectoryTools home page.