Forum Discussion

kcoffrin's avatar
kcoffrin
Contributor
7 years ago

Log.SaveResultsAs Dynamically Name Log File

Currently have the following line of code in a JSCRIPT: Log.SaveResultsAs("C:\\TestLogs\\Log1\Log.xml", lsXML). 

 

This is obviously using hard coded values of Log1 as the Sub directory.  I want this to be dynamic and create a new sub directory each time I run this script without having to change it manually each time.  How would I accomplish this?

4 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    You could do something like this:

    var dateString = aqConvert.DateTimeToFormatStr(aqDateTime.Now(), '%m%d%Y%H%M')
    Log.SaveResultsAs("C:\\TestLogs\\Log" + dateString + "\\Log.xml", lsXML)
    • kcoffrin's avatar
      kcoffrin
      Contributor

      Thanks.  Placing the variable creation and log.saveresultas inside of my function does not provide a sub folder creation.  Placing the variable outside of the function and then the log.saveresultas outside as well, produces a sub folder entitled "Log' + dateString + '

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        I'm not sure I understand.  The placement of the variable declaration and usage should have nothing to do without how it works.  Is it possible to post your whole function?