Windows 7 Forums

Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


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

24 Aug 2014   #1
MichaelHonor

Windows Server 2008 R2
 
 
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 System SpecsSystem Spec
.
12 Sep 2014   #2
Tookeri

Windows 7 Pro 32
 
 

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 System SpecsSystem Spec
Reply

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




Thread Tools Search this Thread
Search this Thread:

Advanced Search




Similar help and support threads
Thread Forum
Windows cannot parse the answer file's <diskconfiguration> setting
Hello, I am currently studying to take the 70-680 in a week's time and am trying to build an answer file. Having done so and included in in the root directory of my Windows 7 USB installation disk, i get the following error: Windows cannot parse the answer file's <diskconfiguration> setting. ...
Installation & Setup
How to run a batch file at logoff & some batch scripting help please
Hiya, I'd just like to run a simple batch file at logoff to backup some settings. I plan to use Robocopy, which is what i use to more thorough backups. Two questions: 1. How make it run by clicking Start > Shutdown? (i realise i could make a shutdown batch file and run it instead, but i'd...
Backup and Restore
Batch File that grabs file names from folder to insert into batch file
Ok I'm totally at a loss on how to word this so I'm just going to write it out the best that I can... :confused: First I have a batch file that I'm writing that will convert mp4 files to mp3 files (I have a lot) for a buddies band using ffmpeg. Here's the code that I'm using: ffmpeg -i...
General Discussion
Trying to use batch code to parse and archive log files... Errors...
Hi all. I have a quick question about compressing a bunch of log files that have specific years at the end of their file names... Let's say I have the following set of files needing to be archived by year: BVC2v2Batch.01042008.log BVC2v2Batch.02042008.log BVC2v2Batch.01042009.log...
Software
Windows cannot parse the unattend answer file's <DiskConfiguration>...
Hi there. I'm trying to do a clean install of Windows 7 Ultimate on a Sony Vaio AR41s via a DVD that I burned (slowest speed, was very careful about that) but upon starting the installation I get the error message: Windows cannot parse the unattend answer file's <DiskConfiguration> setting ...
Installation & Setup
How to create a batch file that will move files based on the file type
How to create a batch file that will move files based on the file type? My Requirement : I need a batch file to copy all .doc files in all my HardDisk to a removable disk say (Z: drive) . Can anyone make it possible using a batch file?Please...Its urgent...
General Discussion


Our Sites

Site Links

About Us

Find 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 23:10.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App