Use a .bat file to recursively cycle through folders and get .class files

Hi all,

This is what I am trying to do. I have a .bat file that takes an argument that is nothing more than a folder name. What I do first goes one level up (cd ..). Now in this directory I have 3 folders, and in each folder there are subfolders and they have .class files.

What I want to do is recursively loop through folders and get .class files. When this is done, I want the echo destination folder of the .class file, as well as the echo filename of the .class file.

So c: \ temp \ potter \ myclass.class. I would highlight c: \ temp \ potter \ and myclass.

I can do this by writing a separate bat file that works. But when I integrate this with a recursive function, it seems to break.

This is what I do:

:: call the junit classes... and save the results echo step 3... cd %1 cd .. for /r %%a in (*.class) do set Var=%%a echo Full file location %Var% for %%i in ("%Var%") do Set CF=%%~dpi Set CF=%CF:~0,-1% :LOOP If "%CF:~-1,1%"=="\" GoTo :DONE Set CF=%CF:~0,-1% GoTo :LOOP :DONE Set CF=%CF:~0,-1% echo Folder Location %CF% ::cd %CF% For %%j in ("%Var%") Do Set name=%%~nxj :: -6 because of Quotations Set name=%name:~0,-6% echo File Name %name% echo step 3 complete... 

However, I only get the output of one directory, while I have several directories having .class files. This is not like a recursive loop.

This is the result I get:

step 3 ...

The full location of the file is C: \ NKCV \ Project \ MyActivities \ 6_Selenium \ htmlTestCasesConve rted2JUnit \ Iexplore \ FLOW2 \ testCase_app2.class

Folder location C: \ NKCV \ Project \ MyActivities \ 6_Selenium \ htmlTestCasesConverte d2JUnit \ Iexplore \ FLOW2

File name testCase_app2

step 3 is completed ...

missing argument!

using htmltestCaseLocation

e.g. "C: \ NKCV \ Project \ MyActivities \ 6_Selenium \ htmlTestCases"

Can someone please let me know what is wrong here?

Thanks.

+4
source share
1 answer

Indeed, you should use Ant or Maven to run JUnit tests or do it in a clean JUnit way and organize all your tests in Suite and run the package through the JUnit command line, but to repeat all the files into a batch file, just use the command for the command as follows:

 for /R %%i in (*.class) do echo "%%i" 

Just replace the echo with a call that does the right thing. Please note that you need to specify a variable if there is a space in the path name.

+14
source

Source: https://habr.com/ru/post/1307365/


All Articles