finding similar file names, run monarch

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
dssrun
Posts: 4
Joined: 15 Nov 2010 14:18

finding similar file names, run monarch

#1 Post by dssrun » 11 Feb 2011 10:17

I need help on a For statement that looks for similarly named files in one folder and for each file runs a monarch command line on it. I am new to this so I am using what I learned from the For /?. I am using a wildcard because all these files are similar in name except where the * is. Any guidance will be appreciated. Thanks in advance. And am I able to pass this variable to the command in my monarch command line?

Code: Select all

FOR /D %%a IN (C:\Documents\%DATE:~-2%%DATE:~-2%\Reports\ /b report1.eom.*.000) DO (monarch commands with %%a as my file to import)

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: finding similar file names, run monarch

#2 Post by aGerman » 11 Feb 2011 13:25

No idea what monarch is. But first we should try to find the right files by ECHOing.
My first question is why do you use %DATE:~-2% twice? This is expanded to the last two digits of the value in %date%.
Try

Code: Select all

echo %DATE:~-2%

to display the result.

How ever. If you need to get the files I would process the output of DIR.

Code: Select all

for /f "delims=" %%a in ('dir /a-d /b "C:\Documents\%DATE:~-2%%DATE:~-2%\Reports\report1.eom.*.000"') do echo %%a

If this line returns the right files then we could look forward to solve your 2nd question.

Regards
aGerman

dssrun
Posts: 4
Joined: 15 Nov 2010 14:18

Re: finding similar file names, run monarch

#3 Post by dssrun » 12 Feb 2011 22:20

Thanks, I will try this on Monday and let you know the results. Monarch is a program that takes a text file with a report and allows you to create traps to get the information you want in a table format. I use the date format that way because that was the only way I figured out how to get the date like 020111 (that is how are new folders are named monthly).

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: finding similar file names, run monarch

#4 Post by aGerman » 13 Feb 2011 05:07

dssrun wrote:I use the date format that way because that was the only way I figured out how to get the date like 020111 (that is how are new folders are named monthly).

Hmm, then %DATE:~-2%%DATE:~-2% is definitely wrong.
What means "monthly"? IMHO 020111 has nothing to do with monthly :? Looks like DDMMYY or MMDDYY, not sure.
And the second issue is how does the date looks like for your settings?
echo %date% displays DD.MM.YYYY with my German settings, but it could be MM/DD/YYYY or YYYY-MM-DD or ... as well.
Come back with informations about the name formatting of your folder and the formatting of %date%.

Regards
aGerman

dssrun
Posts: 4
Joined: 15 Nov 2010 14:18

Re: finding similar file names, run monarch

#5 Post by dssrun » 14 Feb 2011 09:52

Thanks for the reply,

This code results in 11:

Code: Select all

echo %Date:~-2%


The name of the folders I am trying to access are setup as MMDDYY (they are created daily) and when I do my date echo line below I get MMDDYY

Code: Select all

 echo %date:~4,2%%date:~7,2%%date:~-2%


When I do the code below I get DDD MM/DD/YYYY

Code: Select all

echo %date%


BTW your FOR statement worked and after I inserted my monarch command line after DO it worked as well. Thanks for the help!

Post Reply