user2623499
user2623499

Reputation: 11

Batch Script Parsing Dir Command

Hello newbie looking for some help. I am trying to write a script to search all files and folders in my drive which have a certain identifier. For example "ID -"

I was using the following to get files and directories listed in a log file:

dir ID * /A:-D-H /B /S >> C:\FileCatalogue.log 2>> C:\FileCatalogue.log
dir ID * /A:D-H /T:C /S >> C:\DirCatalogue.log 2>> C:\DirCatalogue.log

However I want the output to be in 3 tabbed columns:

FILE {tab} DIR {tab} ID

ID123 - YYYY - myfile.txt {tab} C:/tmp/tmp {tab} ID123 - YYYY

etc..

etc...

Any help would be greatly appreciated! Victor

Upvotes: 1

Views: 2726

Answers (2)

David Ruhmann
David Ruhmann

Reputation: 11367

@echo off
for /f "delims=" %%A in ('dir /a:-d-h /b /s /t:c ID123*') do for /f "tokens=1,2,* delims=-" %%B in ("%%~nxA") do echo(%%~nxA    %%~dpA  %%B-%%C

Output

ID123 - YYYY - myfile.txt   C:\Users\User\Desktop\  ID123 - YYYY

Upvotes: 1

Endoro
Endoro

Reputation: 37569

try this:

for /f "tokens=1*delims=-" %%a in ('dir /a-d/b ID*') do echo %%a-%%b  %cd%  %%a

Upvotes: 1

Related Questions