automating a batch file process

March 13, 2009 at 09:37:54
Specs: Windows XP
I'm very new to batch programming and processing, so what I have already is quite basic.

c:
cd program files\monarch\program
monarch /rpt:"w:\medical records\tri data\$$A2OLB1_0313_0000.TXT" /mod:"w:\medical records\tri data\A2OLBA4.xmod" /exp:"w:\medical records\tri data\03-13-2009.aca"

This process will launch monarch from my pc, tell it to grab a report from a network drive, modify the report, and export the data as a new file. Notice that the filename for the source report and final report are formatted differently, but they both contain a date parameter (march 13, in this example).

Here's what I need to do:

1. add a step that renames the .aca file to .txt (only modifying the extension, the rest of the filename remains the same). I tried a standard rename command but apparently that doesn't work in batch files.

2. add another step that, after the file is renamed, connects and authenticates into an ftp server and transfers the .txt file

3. Automate the whole process so that I don't have to manually edit the filenames to reflect the date.

Can this be done? A thousand thanks for any help you folks can offer.


See More: automating a batch file process

Report •


#1
March 14, 2009 at 00:19:05
quote:
I tried a standard rename command but apparently that doesn't work in batch files.
what error message does it says?

yes, all of these can be done in batch.
post your code here and which part are you stuck?


Report •

#2
March 14, 2009 at 05:13:52
Yes, first clarify the RENAME snag, as per reno.

The script below shows how to ftp the file. Automating it to act on [monarch] a number of files will take a bit more doing.

===========================
@echo off & setLocal EnableDelayedExpansion

> #.ftp echo o mysite.com
>> #.ftp echo username
>> #.ftp echo password
>> #.ftp echo bin
>> #.ftp echo put "my file"
>> #.ftp echo bye

ftp -s:#.ftp
del #.ftp


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#3
March 16, 2009 at 07:29:24
To clarify, what I tried doing was a typical DOS rename command.

rename w:\medical records\tri data\03-13-2009.aca 03-13-2009.txt

But nothing happens. I don't see an error message, I just notice that the file is never renamed.

Thanks for the ftp commands, I'll give them a try.

How about the automated file rename based on the date, does anyone know how to handle that? What I hope to accomplish is to set this batch file up in a scheduler, and the filenames in the script will reflect the date that the batch executes on. For example, if the batch is launched on Mar 15, then the filenames in the batch should be 0315 and 03-15 respectively. As it currently stands, I have to manually edit the batch every day to reflect the date in the filenames. It would be great to get that automated.


Report •

Related Solutions

#4
March 18, 2009 at 10:56:39
Forget about DOS. For thr rename put your siurce and dest in double quotes.

This script will get the date intom vars:

===============================
::== YMD8.bat

@echo off > d.d

>> d.d echo E 0100 B4 2A CD 21 B4 4C CD 21
>> d.d echo N DAY.COM
>> d.d echo RCX
>> d.d echo 8
>> d.d echo W
>> d.d echo E 0100 B4 2A CD 21 88 F0 B4 4C CD 21
>> d.d echo N MONTH.COM
>> d.d echo RCX
>> d.d echo A
>> d.d echo W
>> d.d echo E 0100 B4 2A CD 21 89 C8 B4 4C CD 21
>> d.d echo N YEAR.COM
>> d.d echo RCX
>> d.d echo A
>> d.d echo W
>> d.d echo E 0100 B4 2A CD 21 88 D0 B4 4C CD 21
>> d.d echo N DAT.COM
>> d.d echo RCX
>> d.d echo A
>> d.d echo W
>> d.d echo Q

debug < d.d > nul
del d.d

dat
for %%a in (1 2 3 4 5 6 7 8 9 ) do if errorlevel %%a set dat=0%%a
for %%a in ( 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) do if errorlevel %%a set dat=%%a
echo Date %dat%

day
if errorlevel 0 set day=Sunday
if errorlevel 1 set day=Monday
if errorlevel 2 set day=Tuesday
if errorlevel 3 set day=Wednesday
if errorlevel 4 set day=Thursday
if errorlevel 5 set day=Friday
if errorlevel 6 set day=Saturday
echo Day %day%

month
for %%a in (1 2 3 4 5 6 7 8 9 ) do if errorlevel %%a set month=0%%a
for %%a in ( 10 11 12) do if errorlevel %%a set month=%%a
echo Month %month%

year
if errorlevel 215 set Year=2007
if errorlevel 216 set Year=2008
if errorlevel 217 set Year=2009
if errorlevel 218 set Year=2010
echo Year %Year%

del day.com
del month.com
del year.com
del dat.com
::== DONE


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#5
March 19, 2009 at 08:25:52
You can do this alot easier i think . I do the same process with Monarch but I do it with consistent file names. so for example I move the original file to a working folder and so I start with a :

copy w:\medical records\tri data\$$A2OLB1_0313_0000.TXT w:\medical records\tri data\working\A20LB.txt

*****I do this so that monarch has a consistent file name to look for on the automation. *******
******Then you automate*********

"C:\Program Files\Monarch\Program\MONARCH.EXE" "w:\medical records\tri data\working\A20LB.txt" "w:\medical records\tri data\A2OLBA4.xmod" /T "w:\medical records\tri data\A20LB.aca"

I almost forgot put this at the very top of your batch file.
for /F "tokens=1-4 delims=/- " %%A in ('date/T') do set DATE=%%B%%C%%D
for /F "tokens=1-4 delims=/- " %%A in ('date/T') do set TODAY=%%B%%C


that will allow you to set a date function to your batch file.

Now after your monarch export line you can then change that report w:\medical records\tri data\A20LB.aca to the correct file name with the correct date.

copy "w:\medical records\tri data\A20LB.aca" "w:\medical records\tri data\%DATE%.aca"
or you could do
copy "w:\medical records\tri data\A20LB.aca" "w:\medical records\tri data\%DATE%.txt"
or both for that matter. I believe it should keep the correct structure.

On the above statements you can name it %today%OR %DATE% depending the stucture you want i use both ways so i have to have 2 names on my script.

Now on the FTP side you'll probably want to follow the instructions above. I don't do any of that.

if you have any more questions just let me know. i am still trying to figure out how to give monarch the functionality of putting the worksheet name as the current date and nobody seems to have an answer for that.


Report •

#6
March 30, 2009 at 10:28:09
I haven't done anything yet in regards to the date scripting, right now I'm still trying to get the FTP portion to function correctly. Here's the code so far:

c:
cd program files\monarch\program
monarch /rpt:"w:\medical records\tri data\$$A2OLB1_0330_0000.TXT" /mod:"w:\medical records\tri data\A2OLBA4.xmod" /exp:"w:\medical records\tri data\03-30-2009.aca"
w:
cd medical records\tri data
rename "03-30-2009.aca" "03-30-2009.txt"
@echo off & setLocal EnableDelayedExpansion

> #.ftp echo open ftp.website.com
>> #.ftp echo <user>
>> #.ftp echo <password>
>> #.ftp echo ascii
>> #.ftp echo lcd w:\medical records\tri data
>> #.ftp echo put "03-30-2009.txt"
>> #.ftp echo bye

ftp -s:#.ftp
del #.ftp

pause

Executing this file succeeds up until the PUT command, where it hangs for about 30 seconds or so then tells me the remote host closed the connection. I spoke with the tech guys who admin the FTP server and they told me there's nothing in place to restrict my access or prevent FTP transfers. Additionally, I can still FTP via web browser just fine to the same site using the same credentials. Am I just overlooking something? The syntax looks correct to me...


Report •

#7
March 30, 2009 at 12:50:58
I don't see how either CD would work. If the second one did, I don't guess you'd need the lcd in the ftp script.

If the CD fails, the file to send won't be found and the ftp session may simply be timing out.

Moving right along, your ftp script looks OK. Sometimes when I'm sending the connection just acts up and I have to try again.


=====================================
If at first you don't succeed, you're about average.

M2


Report •


Ask Question