Unable to correctly parse lines in a .txt file through batch


  1. Posts : 1
    Windows Server 2008 R2
       #1

    Unable to correctly parse lines in a .txt file through batch


    Good Afternoon All,

    This is my first post so if I inadvertently insult anyone through my mannerism I apologize in advance.

    So the puzzle is that my company creates programs for our clients and would like me to create a batch file that can be placed on the desktop and auto-copy all of the files to the new destination overwriting the old ones.

    This is no problem for me, the problem I have is that they are all in different areas, so I wrote some code to extract the information from the Registry key and write it to a .txt file.

    I now need to parse to the last name and just be able to copy out the directories name and give it a value I can then use in the rest of my code.

    Thanks so much for any help in advance.

    P.S: This is what I see from the registry file:

    Windows Registry Editor Version 5.00

    [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\xxxxxxx\xxxxxxxx]
    "DATABASEINSTANCE"="xxx\\xxxxxxxxx"
    "AUTHENTICATIONTYPE"="0"
    "USERNAME"=""
    "PASSWORD"=""
    "TARGETDIR"="D:\\Program Files\\xxxxxx\\xxxxxxx\\"

    I just need this part as a variable to be able to finish off the code D:\\Program Files\\xxxxxx\\xxxxxxx\\

    and boy am i struggling :)
      My Computer


  2. Posts : 1,049
    Windows 7 Pro 32
       #2

    Don't know if you already solved this or not... Anyway, here's a solution.

    Code:
    @ECHO OFF
    setlocal ENABLEDELAYEDEXPANSION
    for /f "delims=!!!" %%x in ('type test.txt ^| find "TARGETDIR"') do set REG=%%x
    set REG=%REG:"TARGETDIR"=%
    for /f "delims==" %%a in ("%REG%") do set DIR=%%a
    set DIR=%DIR:"=%
    echo DIR = %DIR%
    Change the filename from test.txt to your file
    The code will read that file and search for the line with TARGETDIR
    Then remove "TARGETDIR"
    Then only keep what's after the equal sign
    And finally delete the quote signs in the path
    The path is then stored in the variable DIR
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 10:02.
Find Us