What do I use for a delimiter?

Microsoft Windows xp professional w/serv...
April 5, 2010 at 10:36:15
Specs: Windows XP
I'm trying to create a Windows batch file that will search the current folder and sub-folders for .jar files using the for command.

Currently, I have the following:

for /f "usebackq delims=???" %a in ('"for /r %j in (*.jar) do @echo %j"`) do @set jars=%a

where ??? should be replaced by whatever I need to use to specify a carriage return. In Unix I would use \n. What do I use in Windows?

See More: What do I use for a delimiter?

Report •

April 5, 2010 at 10:45:21
The carriage return is implicitally used as a delimitor ... or, do you mean you are handling a unix/linux file on Windows ?

In the latter case, convert to DOS, in the first case : dont use DELIMS

Report •

April 5, 2010 at 10:50:02
No, it's all completely on Windows (I was just using the Unix reference because I'm more experienced with Unix).

My problem with not using the delims is that it defaults to using spaces and tabs and since Windows file and folder names can (and usually do) contain spaces, the command is parsing on those.

Currently, I have 5-6 jar files in sub-folders to the folder that I want to run the batch file out of and the echo in the inner for spits out each jar file as a separate line. I want to be able to collect each of those lines in my jars variable.

Report •

April 5, 2010 at 10:51:35
for /f "usebackq delims=???" %a in ('"for /r %j in (*.jar) do @echo %j"`) do @set jars=%a
I'm not entirely sure what you're attempting to do here. Why the extra FOR loop?

Report •

Related Solutions

April 5, 2010 at 10:53:58
It's the best I could come up with.

What I'm trying to do is create a variable for a batch file that will contain all of the .jar files in the current folder and all sub-folders. If there is a better way to do it, I'm all ears...

Report •

April 5, 2010 at 14:08:34
set jars=
for /r %%a in (*.jar) do @set jars="%%a" !jars!
@echo !jars!

Report •

April 5, 2010 at 14:24:38
That was it.


Now, I have the jar files in quotes separated by spaces and I need to replace the spaces with semi-colons.

Is there some way to do that in your code? I'm not familiar with the !var! syntax.

Report •

April 5, 2010 at 15:22:15
The variable !var! works exactly like %var% ... dont worry there. You are just forced to use the exclamation marks in some cases, but they behave similar.

You are needing this, for the question regarding the spaces conversion to semi-colons:

Environment variable substitution has been enhanced as follows:


would expand the PATH environment variable, substituting each occurrence
of "str1" in the expanded result with "str2". "str2" can be the empty
string to effectively delete all occurrences of "str1" from the expanded
output. "str1" can begin with an asterisk, in which case it will match
everything from the beginning of the expanded output to the first
occurrence of the remaining portion of str1.

Report •

April 5, 2010 at 15:34:57
set jars=
for /r %%a in (*.jar) do @set jars="%%a";!jars!
set jars=!jars:~0,-1!
@echo !jars!

Report •

April 5, 2010 at 15:35:38
Okay, now that I know what the !var! means, I truly understand what was going on in the previous post from Razor2.3.

I modified

... @set jars="%%a" !jars!

...@set jars="%%a";!jars!

and it works like I want.

Thanks to all for the quick answers. It's nice to know there's a place with quick responses to questions.

Report •

Ask Question