user3327200
user3327200

Reputation: 43

find a directory name in batch script

I am writing a batch script. It will be used to check sanity of a Project directory structure. I have to check whether all the required directories are present inside the Project directory or not. If the required directory is present, I need to check whether the name of the directory is in small letters.

I am using the if exist command to check the existence of required directories as following:-

If exist PRJ_directory/source (
echo source exist in project >> log.txt
)

Here I should echo the output to log.txt only if the source directory name is in small letters. How can I do that?

Upvotes: 0

Views: 70

Answers (1)

mbroshi
mbroshi

Reputation: 979

You can use the FINDSTR command for limited regular expressions, in particular to check whether a directory consists all lower case letters.

for /f %%i in (
    'dir /b PRJ_directory ^| findstr /r "^[a-z]*$"'
) do (
    if %%i==source (
        echo source exist in project >> log.txt
    )
)

Upvotes: 1

Related Questions