search specific patter in filename

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
darioit
Posts: 230
Joined: 02 Aug 2010 05:25

search specific patter in filename

#1 Post by darioit » 20 Aug 2012 02:05

Hello,

I have this problem:
I have a lot of this file name in my input directory:
E:\aa.pdf.cc.dd.ee.A01.gg.ff
E:\aa.bb.cc.pdf.ee.A02.gg.ff

I use this script to call another process passing input file and parameter:

Code: Select all

for %%x in (E:\*.pdf.*) do for /F "tokens=6 delims=." %%y in ('dir /b %%x') do call : go %%~nxx %%y
and the result is
go aa.pdf.cc.dd.ee.A01.gg A01
go aa.bb.cc.pdf.ee.A02.gg.ff A02
This script works if the position A01 of token=6 is always in that position, but sometimes doesn’t.
For example:
E:\aa.pdf.dd.ee.A01.gg.ff
E:\aa.pdf.cc.A02.gg.ff.gg.ll
and I must do the same work. as "go aa.pdf.dd.ee.A01.gg.ff A01"

How can modify my script to get A01, A02. Etc. (the letter A+numer is a constant)

2 issue, the best is to have (go aa.pdf.pdf.dd.A01.gg.ff 01) without A in front the number

Regards
Dario

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: search specific patter in filename

#2 Post by foxidrive » 20 Aug 2012 05:18

If you can post a sample of the real filenames then we might be able to help you.

There has to be a format that we can utilise in a batch file and without the real filenames we can't devise one.

darioit
Posts: 230
Joined: 02 Aug 2010 05:25

Re: search specific patter in filename

#3 Post by darioit » 20 Aug 2012 07:17

Input file:
CD.W.OLW.PROD.EWD.A02.G01000V00
CD.W.OLW.PROD.OPR.A04.G01000V00
CD.W.OLW.PROD.UKD.A06.G01000V00
CD.W.OLW.PROD.YHD.A07.G01000V00
CD.W.OLW.PROD.FBA.A11.G01000V00
CD.W.OLW.PROD.A12.G01000V00
CD.W.OLW.PROD.FBD.A13.G01000V00
CD.W.OLW.PROD.MPO.A14.G01000V00
CD.W.OLW.PROD.MPU.DA.A15.G01000V00
CD.W.OLW.PROD.FBA.A16.G01000V00
CD.W.OLW.PROD.FBA.A17.G01000V00
Script code:

Code: Select all

@echo on
for %%x in (E:\*.PROD.*) do for /F "tokens=6 delims=." %%y in ('dir /b %%x') do call :go %%~nxx %%y
goto :eof

:go
echo %1 %2
goto :eof


This two file A** are not in position 6
CD.W.OLW.PROD.A12.G01000V00
CD.W.OLW.PROD.MPU.DA.A15.G01000V00

Thanks in advance.

Regards

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: search specific patter in filename

#4 Post by foxidrive » 20 Aug 2012 17:10

This will echo CALL GO with the name and number:

Code: Select all

@echo off
setlocal EnableExtensions EnableDelayedExpansion
for /f "delims=" %%a in ('dir /a:-d /b') do (
set "name=%%a"
set "name=!name:.=\!"
for /f "delims=" %%b in ("!name!") do (
for /f "delims=" %%c in ("%%~pb\.") do (
set "number=%%~nxc"
set "number=!number:~1!"
echo call go %%a !number!
)
)
)
pause




call go CD.W.OLW.PROD.EWD.A02.G01000V00 02
call go CD.W.OLW.PROD.OPR.A04.G01000V00 04
call go CD.W.OLW.PROD.UKD.A06.G01000V00 06
call go CD.W.OLW.PROD.YHD.A07.G01000V00 07
call go CD.W.OLW.PROD.FBA.A11.G01000V00 11
call go CD.W.OLW.PROD.A12.G01000V00 12
call go CD.W.OLW.PROD.FBD.A13.G01000V00 13
call go CD.W.OLW.PROD.MPO.A14.G01000V00 14
call go CD.W.OLW.PROD.MPU.DA.A15.G01000V00 15
call go CD.W.OLW.PROD.FBA.A16.G01000V00 16
call go CD.W.OLW.PROD.FBA.A17.G01000V00 17

Press any key to continue . . .

darioit
Posts: 230
Joined: 02 Aug 2010 05:25

Re: search specific patter in filename

#5 Post by darioit » 22 Aug 2012 04:20

WOW !!!!

thanks

Regards

Post Reply