Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Batch File to read individual lines of .txt document  (Read 6550 times)

0 Members and 2 Guests are viewing this topic.

slackhouse

    Topic Starter


    Greenhorn

    Batch File to read individual lines of .txt document
    « on: September 15, 2008, 01:29:49 PM »
    I've written a basic batch file to read a directory and output all the files into another .txt. file.

    Code: [Select]
    @echo off
    cd C:\Production Change Actions\Input
    dir /b > "C:\Documents and Settings\username\Desktop\Imports.txt"

    I'm now trying to get all of those file names placed into this line of another batch file.

    Code: [Select]
    @echo off

    cls
    :start
    cd C:\Program Files\Thunderhead35
    Thunderhead.Importer.exe -user DPS\username -conflict overwrite -verbose -file
    INSERT FILE NAME FROM IMPORTS.ZIP

    The file names have to be placed into the second batch file individually and the Thunderhead.Importer.exe does not allow "*.zip" for me to do them all at once.  So, I'll need the batch to be able to read each line, insert it into the second batch, then have the batch file run, then start over all the way through all of the file names.

    ghostdog74



      Specialist

      Thanked: 27
      Re: Batch File to read individual lines of .txt document
      « Reply #1 on: September 15, 2008, 08:18:58 PM »
      what actually are you wanting to do?

      Sidewinder



        Guru

        Thanked: 139
      • Experience: Familiar
      • OS: Windows 10
      Re: Batch File to read individual lines of .txt document
      « Reply #2 on: September 16, 2008, 03:12:52 AM »
      This should work:

      Code: [Select]
      @echo off
      cd /d C:\Program Files\Thunderhead35
      for /f "tokens=* delims=" %%v in ('dir /b "C:\Production Change Actions\Input"') do (
      Thunderhead.Importer.exe -user DPS\%username% -conflict overwrite -verbose -file "%%v"
      )

      Double check username. Wasn't sure if that is a literal or the system variable.

       8)
      The true sign of intelligence is not knowledge but imagination.

      -- Albert Einstein

      slackhouse

        Topic Starter


        Greenhorn

        Re: Batch File to read individual lines of .txt document
        « Reply #3 on: September 16, 2008, 08:56:30 AM »
        thanks...i'm gonna try that out.  The "username" is a specific username that I'll change it to.  I just changed it to username for privacy.  I'll let you know how this works in a little while.

        slackhouse

          Topic Starter


          Greenhorn

          Re: Batch File to read individual lines of .txt document
          « Reply #4 on: September 16, 2008, 09:22:34 AM »
          Okay...I got it to work...I had to make a minor change in order to get it to read the file correctly:

          Code: [Select]
          @echo off
          cd /d C:\Program Files\Thunderhead35
          pause
          for /f "tokens=* delims=" %%v in ('dir /b "C:\Production Change Actions\Input"') do (
          Thunderhead.Importer.exe -user domain\username-conflict overwrite -verbose -file [b]C:\Production Change Actions\Input\\[/b]"%%v"
          )
          pause

          without adding that part, it kept saying, "cannot find C:\Program Files\Thunderhead35\whateverthefilename.zip"  And, I had to add in two slashes to get it to read correctly.

          Thanks for the help!!!  Is their anything wrong with the way I tweaked it?

          Sidewinder



            Guru

            Thanked: 139
          • Experience: Familiar
          • OS: Windows 10
          Re: Batch File to read individual lines of .txt document
          « Reply #5 on: September 16, 2008, 12:20:08 PM »
          Quote
          Is their anything wrong with the way I tweaked it?

          Not a thing. Any tweak that works is a good tweak. ;D
          The true sign of intelligence is not knowledge but imagination.

          -- Albert Einstein

          slackhouse

            Topic Starter


            Greenhorn

            Re: Batch File to read individual lines of .txt document
            « Reply #6 on: September 16, 2008, 12:31:26 PM »
            Code: [Select]
            @echo off
            cd /d C:\Program Files\Thunderhead35
            pause
            for /f "tokens=* delims=" %%v in ('dir /b "C:\Production Change Actions\Input"') do (
            Thunderhead.Importer.exe -user domain\username-conflict overwrite -verbose -file C:\Production Change Actions\Input\\"%%v"
            )
            pause

            Could you explain what some of this actually means?

            I guess the for and do are where I'm lost on what this is actually doing.

            Tokens=*???
            delims=nothing???
            why is the variable %%v???

            I'd like to understand this so I don't have to ask a similar question later.  Thanks.

            Sidewinder



              Guru

              Thanked: 139
            • Experience: Familiar
            • OS: Windows 10
            Re: Batch File to read individual lines of .txt document
            « Reply #7 on: September 16, 2008, 01:39:04 PM »
            tokens=*
               tokens=2* defines 3 variables (tokens)
               tokens=1* defines 2 variables
               tokens=*   defines 1 variable

            Could I have used tokens=1? Yes! Go figure!

            delims=nothing
               the default delimiters are tab and space; overriding with no delimiters avoids dropping data when file names have embedded spaces

            why is the variable %%v??? Why not? ;D The variable declared can be any lower or upper case letter. Numerics can be used, but are easily confused with command line arguments.

            Using the tokens=, delims= and the declared variable, each for statement is constructed specific to the data.
             
            The for command is highly nuanced. These sites are much more eloquent than I could be.

            Iterating with FOR

            FOR

             8)


            The true sign of intelligence is not knowledge but imagination.

            -- Albert Einstein

            slackhouse

              Topic Starter


              Greenhorn

              Re: Batch File to read individual lines of .txt document
              « Reply #8 on: September 16, 2008, 01:58:56 PM »
              Thank you for your assistance.  It is greatly appreciated.