• Help with Batch File

    Home » Forums » AskWoody support » Windows » Windows – other » Help with Batch File

    Author
    Topic
    #362720

    Hello there,

    I have a batch file that does a file upload and writes to a log file. A line gets appended each time saying if the upload was successful or not. How do I get a date and time to also get appended so that I know when the job succeeded or failed – any ideas ?

    cheers,

    Adam

    Viewing 2 reply threads
    Author
    Replies
    • #551466

      I’m sure there is a neater solution but you could do worse than doenload a utility called Now which can be used for a variety of date-based batch files.

      I found their example didn’t work on W2K, but

      NOW ECHO CREATED ON [day] [dy] [month] [year] AT [hh]:[mm] >> log.txt

      appended the date and time to a file called log.txt OK.

    • #551468

      Being something of an old hand at DOS I second Lief’s suggestion. If there is a neater solution I would be happy to hear about.

      • #551469

        Funnily enough, I’ve just been working on a couple of batch files – first time in many years. I wanted to rename a file with today’s date, so I had done half the legwork!
        I’ve worked out how to get the date and time to do the file rename, but couldn’t see how to write that information to a file. I suspect W2K may have some limitations when it comes to batch files.

    • #551523

      How about:

      ECHO.|DATE|FIND /I "Current">>C:LogfilesMyLog.Log
      ECHO.|TIME|FIND /I "Current">>C:LogfilesMyLog.Log
      

      No space betweemthe “O” in ECHO and the dot after it.

      • #551557

        legare,

        thanks for the help. I’m having a little trouble getting it to work as it probably should. Here’s how I’ve modified it to use in my batch file:

        if “%LOGGING%”==”YES” echo Already up to date with the latest virus identities >>%SGETDIR%IDEFETCH.LOG
        if “%LOGGING%”==”YES” echo.|DATE|FIND /I >>%SGETDIR%IDEFETCH.LOG
        if “%LOGGING%”==”YES” echo.|TIME|FIND /I >>%SGETDIR%IDEFETCH.LOG

        But here’ s what I get in the log file:

        Already up to date with the latest virus identities
        FIND: Parameter format not correct
        FIND: Parameter format not correct

        Any ideas ?

        cheers,

        Adam

        • #551563

          I think you will need to do it like this:

          if NOT "%LOGGING%"=="YES" GOTO NOTLOGGING
          echo Already up to date with the latest virus identities >>%SGETDIR%IDEFETCH.LOG
          echo.|DATE|FIND /I "CURRENT">>%SGETDIR%IDEFETCH.LOG
          echo.|TIME|FIND /I "CURRENT">>%SGETDIR%IDEFETCH.LOG
          :NOTLOGGING
          
          • #552196

            Can I ask why the echo. and find?
            How about (tested on NT):

            if NOT “%LOGGING%”==”YES” GOTO NOTLOGGING
            echo Already up to date with the latest virus identities >>%SGETDIR%IDEFETCH.LOG
            DATE /t>>%SGETDIR%IDEFETCH.LOG
            TIME /t>>%SGETDIR%IDEFETCH.LOG
            :NOTLOGGING

            Also, does anyone know where to find a comprehensive batch file guide for NT? Something that explains in detail the command extensions for the SET command, for instance. Maybe some clever examples and tricks, that sort of thing… ?

            • #552207

              My code came from back in DOS 5. The ECHO. was a special syntax of ECHO to get it to echo a CR/LF. This was then piped to the DATE/TIME command to reply to its prompt for you to enter a new date/time. The Find was because DATE/TIME displayed multiple lines, and the one that contained the word “Current” was the one that contained the date/time. There was no /t parameter on the DATE/TIME commands. If your code works, then I assume that this parameter eliminates the need for ECHO. and FIND on NT. As far as I know, that will not work on WIN 98 and earlier.

            • #552668

              Some info on batch files here

    Viewing 2 reply threads
    Reply To: Help with Batch File

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: