0

I'm looking to return a set of values which match my criteria, based upon the results of another tool!

My bat file reads a list of files using the ClearCase tool (as per this question), and writes them to screen. I now want to filter the results, where it only shows me the files which end with .cs (note, there may be other periods in the name)

My code

@echo off
setlocal
for /F "usebackq delims=" %%A in (`cleartool ls  -rec ^| find /V "Rule:" ^| find /V "hijacked" ^| find /V "eclipsed" ^| find /V "-->"`) do if %%A==*.cs @echo %%A

I'm lost as to why when I run the following (note the very end of the script is different)...

@echo off
setlocal
for /F "usebackq delims=" %%A in (`cleartool ls  -rec ^| find /V "Rule:" ^| find /V "hijacked" ^| find /V "eclipsed" ^| find /V "-->"`) do @echo %%A

...I see lots of results (including files with the .cs extension). But, when I run the first code script, it runs but writes nothing to screen. When I run the second code example, one of the lines I see is

I did try adding quote marks but it made no difference.

if "%%A"=="*.cs"

When I run the second piece of code, the results look like

.\bin\x86 
.\bin\x86\Debug
.\Debug\mywork.exe.embed.manifest  
.\obj\x86\Debug\myThings.dll  
.\Html\MyFile.cs  
.\obj\x86\Debug\MyProject\Views\File.baml  
.\obj\x86\Debug\MyProject\Views\File.g.cs  
.\obj\x86\Debug\MyProject\Views\File.g.i.cs  

From the above, ideally I want to only see MyFile.cs (although I can easily live with all the .cs files)

Community
  • 1
  • 1
MyDaftQuestions
  • 4,487
  • 17
  • 63
  • 120
  • Personally, I'd use `findstr /V "Rule: hijacked eclipsed -->"` in place of four cascaded `find/v`s. How is batch supposed to determine that you only want `myfile.cs`? What is the criterion for that choice? – Magoo Jan 31 '14 at 17:31

1 Answers1

0

If you want to check extension in a for loop, use %%~xA. It will return just the extension of file with dots.

if "%%~xA"==".cs"
mihai_mandis
  • 1,578
  • 1
  • 10
  • 13
  • ` does not suround a command in batch. Use simple quotes 'cleartool ls -rec ^| find /V "Rule:" ^| find /V "hijacked" ^| find /V "eclipsed" ^| find /V "-->"'. In rest - you'll need to put more details, like output of cleartool. – mihai_mandis Jan 31 '14 at 13:59