Results 1 to 13 of 13
  1. #1
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Batch file variables (Batch)

    Are you sure that the quotes in the first line are placed correctly?

  2. #2
    Bronze Lounger
    Join Date
    Sep 2007
    Posts
    1,203
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Batch file variables (Batch)

    I'm not sure that this is the correct area for this question, please feel free to move.

    Every morning I run a batch file that takes text files via Monarch, model's them and creates new output files as xls / mdb. I have attached an example. This is done on over 100 reports. The reports have different dates that need to be changed on the bat files, there are always 3, e.g 09-12-08 / 091208 / 081208. I manually change all the date's which is time consuming and boring.

    My question is: Can variables be used in bat files, e.g., declare the 3 variable dates, and then use the variable name on each script line instead of the date? Or, is there another way?
    Attached Files Attached Files

  3. #3
    Bronze Lounger
    Join Date
    Sep 2007
    Posts
    1,203
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Batch file variables (Batch)

    Well spotted, no that is an error! & the bottom line is missing a .txt

    I omitted much of the data, so not to post overkill. Now corrected.

  4. #4
    Bronze Lounger
    Join Date
    Sep 2007
    Posts
    1,203
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Batch file variables (Batch)

    This is new to me, I will take a look, Thanks

  5. #5
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Batch file variables (Batch)

    You can Set the dates into Environment Variables and then use them to concatenate into the file names. Find a good Batch file reference on the net. (The example in <post#=731,588>post 731,588</post#> is more complicated than what you want as it is manipulating the system date into an Environment Variable, but the last line uses concatenation of that variable to add the date to the file name.)
    -John ... I float in liquid gardens
    UTC -7±DS

  6. #6
    Bronze Lounger
    Join Date
    Sep 2007
    Posts
    1,203
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Batch file variables (Batch)

    John, Thanks for the link, i'm afraid that I am way out of my depth here as I have little understanding of batch files, other than multiple instructions as per my text file.

    All I was really hoping for was to be able to change 3 variables daily, instead of >100 rigid commands.

    @ echo off ??????? [noidea]

    I will do a little gooooooooooglin.....

  7. #7
    Bronze Lounger
    Join Date
    Sep 2007
    Posts
    1,203
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Batch file variables (Batch)

    Something like:

    SET [date1=[081208]]
    SET [date2=[091208]]
    SET [date3=[09-12-08]]


    "C:Program FilesMonarchProgramMonarch.exe" "Q:BACSIN Úte3%.txt" "F:ModelsBACS IN PRF.mod" "Q:Bacs In PRF Úte2%.xls"

    "C:Program FilesMonarchProgramMonarch.exe" "Q:BACSIN Úte3%.txt" "F:ModelsBACS IN.mod" "Q:Bacs In Úte2%.mdb"
    "C:Program FilesMonarchProgramMonarch.exe" "Q:BACSIN Úte3%.txt" "F:ModelsBACS IN.mod" "Q:Bacs In Úte2%.xls"

    "C:Program FilesMonarchProgramMonarch.exe" "Y:NVM.B46600.BC46601-Úte1%.txt" "F:ModelsPurged.mod" "Q:Purged 2 Úte2%.xls"

    ????

  8. #8
    Bronze Lounger
    Join Date
    Sep 2007
    Posts
    1,203
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Batch file variables (Batch)

    I will test tomorrow John, Thanks very much!!

  9. #9
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Batch file variables (Batch)

    The concept is OK but the syntax is wrong - see my example.
    -John ... I float in liquid gardens
    UTC -7±DS

  10. #10
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Batch file variables (Batch)

    Jumping in late here.
    Have I understood the question?
    1. <LI>You have a batch file which makes 100 calls to a program "Monarch.exe"
      <LI>Each call to "Monarch.exe" passes three parameters, two of which need to reflect a specific date.
      <LI>The two "date" parameters use differing formats of the supplied date.
      <LI>The date is often, but not necessarily, the current date.
    I ask for clarification because this is akin to my startup files, where I build date-related files each day, and time-related files for each time I run WinWord.exe etc.

  11. #11
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Batch file variables (Batch)

    Forget about @echo off and all that stuff. <img src=/S/smile.gif border=0 alt=smile width=15 height=15> What are the three variables that are constant in your batch file? I can see three dates in your attached file; do you need to input all three, or just rename the output file to a certain date?

    What we'll need to do is something like this, bearing in mind I can't emulate your commands as I don't have your files, so you'll have to do the testing:

    SET tempdate1 = 092508
    "C:Program FilesMonarchProgramMonarch.exe" "Y:NVM.B46600.BC46601-081208.txt" "F:ModelsPurged.mod" "Q:Purged 2"%tempdate1%.xls

    (There may be batch file limits on spaces in output file names, or other limits on the way parameters are accepted by Monarch.exe.)
    -John ... I float in liquid gardens
    UTC -7±DS

  12. #12
    Bronze Lounger
    Join Date
    Sep 2007
    Posts
    1,203
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Batch file variables (Batch)

    Chris,

    1. There or there about's, yes.
    2. yes, sometimes the same date, but output file (p3) in a different format to the input file (p1).
    3. yes, for some.
    4. the date is always today and yesterday (or more specifically, today and the last business day)

    I ommited the fact that there are folders for year and month for the output files (p3) that would also need to be variable...

  13. #13
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Batch file variables (Batch)

    This is doable in DOS Batch files (and I can and will do it).
    Parsing the date is not hard - there are two batch files out there (attached) that do it, and I've written one, so that makes two really good solutions.
    My JukeBox reboot assigns one of seven folders according to the day of the week.

    The "last business day" is the only interesting bit. (grin!)
    I might solve that by assuming that the machines only re-boot on business days, and store the boot-date in BootDate.bat, immediately after copying the existing BootDate.bat to LatestBootDate.bat
    Your batch file would then use both BootDate.bat and LatestBootDate.bat to set the appropriate YY, MM, DD environment variables, and you'd be home and hosed.

    An alternate solution is of course to write some VBA and/or VBScript [carefully staying in-forum!] to determine the YY, MM, DD and generate the batch file from the VBA/VBS.

    Shall we dance?
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •