1.

Solve : Piping, FIND command??

Answer»

IN a CMD window I type

Code: [Select]dir /b /a:d ^| find BC????
This works, It displays all directories with BCsomenumber but when using a for LOOP in a bat that is looking in the same directory

Code: [Select]for /f "tokens=1*" %%i in ('dir /b /a:d ^| find /I "BC????"') do ECHO 1:%%i
Doesn't work. Does it interpert my ?'s differently in a for loop? Using the search string "BC" works in a sense but also returns information I don't need at this time.


Thanks for the assistance. maybe this:
Code: [Select]dir /b /a:d ^| find BC???? >text.txt
for /f "tokens=1*" %%i in ('type text.txt') do ECHO 1:%%idevcom, i am sure there is no need to create a temp file.

OP, you can use vbscript
Code: [Select]Set objFS = CreateObject("Scripting.FileSystemObject")
strFolder = "c:\test"
Set objFolder = objFS.GetFolder(strFolder)
Go( objFolder)
Sub Go(objDIR)
  If objDIR <> "\System Volume Information" Then
    For Each eFolder in objDIR.SubFolders
    strFolderName = eFolder.Name
    If INSTR(strFolderName, "BC")>0 Then
    WScript.Echo strFolderName
    End If
      Go eFolder
    Next

  End If 
End Sub
save as mysearch.vbs and on command LINE
Code: [Select]c:\test> cscript /nologo mysearch.vbs

C:\>type bc.bat
Code: [Select]echo off
for /f "tokens=1*" %%i in ('dir /b  ^| find /I "BC"') do ECHO 1:%%i
Output:

C:\>bc.bat
1:bc.bat
1:bc11.txt
1:bc12.txt
1:bc13.txt
1:bcalc.bat

C:\>

C:\>dir /b BC*.*
bc.bat
bc11.txt
bc12.txt
bc13.txt
bcalc.bat

C:\> Quote from: devcom on July 06, 2009, 04:48:31 PM

maybe this:
Code: [Select]dir /b /a:d ^| find BC???? >text.txt
for /f "tokens=1*" %%i in ('type text.txt') do ECHO 1:%%i

I ended up using this. This appears to meet my needs at this time. Thanks for the other replies. I appropriate it.

gh0std0g74
Still haven't taking the the time to really learn VBS, need to as I know it has a lot of power, but in the mean time usually when I ask a DOS question it is because the rest of the BATCH is already written and some function part of it isn't working the way I think it should or isn't working to my needs. THANK you by all means though for your VBS input as at some point I will be shifting my focus into this LANGUAGE.


Discussion

No Comment Found