Search code examples
batch-filedirectorydetect

Get a folder path where is missing specified file into variable


Let's say I have two folders in one.

MyFolder\Folder1\ - contains .class and .java file

MyFolder\Folder2\ - contains only .class file

The question is, if you can make the batch file detect the folder in (MyFolder) where is a .java file missing and put the path into a variable.

Something like:

find sub/folder with no *.java files in MyFolder\ <-and somehow to put the folder path into a variable

Does anyone know what would the script look like? Thanks to everybody that will help.


Solution

  • Here is an idea, you can work on it to make it suit your needs:

    Setlocal EnableDelayedExpansion
    for /D %%f in (MyFolder\*) do if not exist %%f\*.java (
        set nonJavaFolder=%%f
    )
    echo !nonJavaFolder!