Writeln With Variable File name

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
jeffmazerski
Newbie
Posts: 4
Joined: Wed Apr 07, 2010 2:56 pm

Writeln With Variable File name

Post by jeffmazerski » Tue Jul 22, 2014 3:31 pm

I need to create a csv file that will have a new name each date. The name of the file name will have todays date in it. this is what I have so far. The file never gets written or created in the TEMP folder. If I take out the %FILENAME% in the WRITELN statement, and use filename.csv, the file has the data from the READFILE statement. Any help is appreciated. I believe I am missing something simple.

Let>title=LogFile
ConCat>title,date
ReadFile>C:\temp\InvoiceData.csv,strFile1
Year>the_year
MidStr>year,3,2,year
Month>the_month
Day>the_day
Let>filename=C:\temp\LogFile
Let>extension=.csv
ConCat>filename,the_year
ConCat>filename,the_month
ConCat>filename,the_day
ConCat>filename,extension

WriteLn>c:\temp\%filename%,result,%strFile1%

Message>%filename%

hagchr
Automation Wizard
Posts: 330
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Re: Writeln With Variable File name

Post by hagchr » Tue Jul 22, 2014 5:33 pm

Hi, Not sure if you have tried the Debugger in MS. If you step through the program by pressing F8 for each line you can see the variable values in the left pane. There are a couple of problems with the code, eg.

in line 2, date is not yet defined
in line 4 result goes into the variable the_year, but in line 5 you use the value year, which is not used later on
in line 8 you include the path in the file name, the path is also included in the WriteLn statement on line 14, ie double.

Adjusting it slightly gives:
(%DESKTOP_DIR% is the user desktop path. Just change if you want a different location)


ReadFile>C:\temp\InvoiceData.csv,strFile1
Year>yyyy
Midstr>yyyy,3,2,yy
Month>mm
Day>dd
Let>FileName=%DESKTOP_DIR%\LogFile%yy%%mm%%dd%.csv
WriteLn>FileName,result,strFile1
Message>%filename%

  View Snippet Page

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts