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

MichaelHonor

New member
Local time
3:51 AM
Messages
1
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 My Computer

At a glance

Windows Server 2008 R2I78 Gig
Computer type
Laptop
Computer Manufacturer/Model Number
Asus
OS
Windows Server 2008 R2
CPU
I7
Memory
8 Gig
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 My Computer

At a glance

Windows 7 Pro 32Intel(R) Core(TM) i5 CPU M 540 @ 2.53GHz4,00 GB (Usable 2,98)NVIDIA NVS 5100M
Computer type
Laptop
Computer Manufacturer/Model Number
HP Elitebook 8540p
OS
Windows 7 Pro 32
CPU
Intel(R) Core(TM) i5 CPU M 540 @ 2.53GHz
Motherboard
Hewlett-Packard 1521
Memory
4,00 GB (Usable 2,98)
Graphics Card(s)
NVIDIA NVS 5100M
Sound Card
NVIDIA High Definition Audio
Screen Resolution
1600x900
Hard Drives
INTEL SSDSA2CW120G3
Antivirus
F-Secure Internet Security
Browser
IE, Firefox, Opera
Other Info
Sandboxie,
SRP (Software Restriction Policy),
EMET (Enhanced Mitigation Experience Toolkit),
WFC (Windows Firewall Control by BiniSoft),
Malwarebytes Premium
Back
Top