In a batch file, how to create txt file with variable name in foreach loop based on current item in the loop

Viewed 57

I'm trying to create a batch file that takes in two directories, I'll call them C:\projects and C:\results.

I want it to loop through all directories in C:\projects - each directory will be a gradle project. It needs to cd to that directory and echo the results of a 'gradle dependencies' call into a file. It needs to make a separate file for each project. Ex, If I have these files:

C:\projects\calculator
C:\projects\restTest
C:\projects\foo

I want it to output the 'gradle dependencies' to the following files:

C:\results\calculator.txt
C:\results\restTest.txt
C:\results\foo.txt

When I run my script, however, it only creates one file and loads the results of all gradle dependencies call to that file. How do I get it to create a separate file for each? Code follows:


    setLocal EnableDelayedExpansaion
    
    FOR /D %%i IN (C:\projects\*) DO (
    cd %%i
    set "SN=%%~nxi"
    echo >>C:\results\%SN%.txt
    echo|gradle dependencies>>C:\results\%SN%.txt
    )

0 Answers
Related