1.

Solve : Protecting long file names in batch files?

Answer»

Hello,

I need to search through a bunch of inherited data files to determine to what extent a test regimen was completed.  In some of the data files are the file names of test IMAGES, and I need to find those image names to COMPARE with a test plan.  Thus, in my path I've put a batch file containing

for /r %%f in ("*.nb") do find /i ".jpg" %%f

The problem, of course, is that the find command is passed file names which the command interpreter, I guess, breaks down into partial strings if the file name has spaces.  I tried some of the options (which I learned about on this forum, thank you!) but was unable to make any progress.

How can I make this pass the full, long, space-containing file names to the "find" command?  The environment is Win2k, V5.0, SP4, and I'm operating from a DOS window started with cmd.exe, not command.exe.

Thanks,
MPWMy guess is that it's the variable value that contains the emebedded spaces not the mask:

CODE: [SELECT]for /r %%f in (*.nb) do find /i ".jpg" "%%f"

Good luck. 8-)Sidewinder,
Thanks for your suggestion.  That's the first thing that occurred to me, and I was sure I had tried it, but apparently not:  it does seem to work.  At least it does recursively search the directories, not breaking the filenames into separate tokens.

Here's how the line in the batch file ends up:
  for /r %%f in ("*.nb") do find /i ".jpg" "%%f"
The symbol prevents the initial "for" command being echoed, but each "find" echoes its invocation to the screen, making the output file (I use redirection) contain a lot of excess lines.  For example,

{really long prompt arising from $p$g}find /i ".jpg" "{really long path}\Experimental Builds.nb"

---------- {really long path}\EXPERIMENTAL BUILDS.NB

This file does not have any lines containing .jpg, but "find" still has to tell me it searched there.

I can filter those out with a separate batch file, but it's annoying.  I'll see if I can figure that one out myself.  Tried "echo off", same result: it doesn't appear to be passed to subsequent processes.

Thanks again for your help, and sorry it wasn't more of a challenge.
MPWNot sure if Win2000 has the FINDSTR command, but this may give you the results you're looking for:

Code: [Select]for /r %%f in (*.nb) do findstr /m  /i ".jpg" "%%f"

 8-)Thanks again.  Yes, Win2k has findstr, and I've used it sometimes because of its enhanced options.  In this case, it's really the "for" construct and the command SHELL.  It appears each loop of the "for" command is echoed to stdout, or perhaps it's just as though you'd typed in the "find" command for each file in the expanded tree.  No matter, I can figure out some way to do it.  Will let you know what I end up with.
MPWOK, here's what I finally ended up with.  It completely eliminates the clutter in the command window, and gives me the filenames, which I can then go search (or use as a fileset to feed to another script if I want the individual lines).  I first had hardcoded the strings, but then changed to the command line replaceable parameters.  Thanks for your original clue!
MPW

echo off
if exist rsearch.txt del rsearch.txt
for /r %%f in ("%1") do findstr /i /m /l "%2" "%%f" >>rsearch.txt
echo on



Discussion

No Comment Found