Page 1 of 1

finding similar file names, run monarch

Posted: 11 Feb 2011 10:17
by dssrun
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)

Re: finding similar file names, run monarch

Posted: 11 Feb 2011 13:25
by aGerman
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

Re: finding similar file names, run monarch

Posted: 12 Feb 2011 22:20
by dssrun
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).

Re: finding similar file names, run monarch

Posted: 13 Feb 2011 05:07
by aGerman
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

Re: finding similar file names, run monarch

Posted: 14 Feb 2011 09:52
by dssrun
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!