Yovan Ho
Yovan Ho

Reputation: 13

loop trough files in windows batch

I'm a newbie with Windows batch. I have been struggling with the FOR loop these days.

I want to loop through a couple of files with a series of commands.

I tried to run the codes in the command line:

for /f  %a in (F:\meta\test\test\List.txt) do (
set b=%a 
 set c=%b:.txt=_ALE.nii% 
set d=%b:.txt=_p005_C05_10_clust.nii% 
java -cp GingerALE.jar org.brainmap.meta.getClustersStats %a %c% %d%)

It turns out that the command did work. However, not every file (the file paths were listed in List.txt) was perform through all the commands.

For example, my first file listed in List.txt would be "cognitive.txt", last is "social.txt". It confused me a lot that each time the parameter %a was exactly what I wanted, but %c% would be "social_ALE.nii", %d% would be"social_p005_C05_10_clust.nii", instead of matching the prefix of %a.

Besides, if I tried to replace all single percent "%" with "%%" and saved them in a batch file, it didn't work then.

Wish somebody could help me out of this confusing situation!

Thanks!

Yovan

Upvotes: 0

Views: 56

Answers (1)

Yovan Ho
Yovan Ho

Reputation: 13

I have solved the problem! It was quite a surprise for me! I was used to the settings of variables in MATLAB. I was quite surprised to find out that the strings could be concatenated like

test\%~na_ALE.nii
test\%~na_p005_C05_10_clust.nii

thus, the code below solved my problem:

for /f %a in (F:\meta\test\test\List.txt) do (java -cp GingerALE.jar org.brainmap.meta.getClustersStats %a test\%~na_ALE.nii test\%~na_p005_C05_10_clust.nii)

Instead of removing the question, I chose to post this message in case somebody might encounter similar problems!

Upvotes: 1

Related Questions