0

I've read a lot of things and I can't find away of doing this that I understand. This might be because I'm a wee newbie though.

What I'm trying to do is:

I have a file called start.txt with the contents

..\dll | toapp.exe "..\posdata\filename.xml" "..\OUT" "..\TEMP" 

I want to read the contents of that in a batchfile and take only filename.xml as a variable. From device to device inside the network it changes.

I'm then going to use that variable to copy a file from 1 machine to another but I only want that one file and I can't be sure what it's called without looking in the start.txt. I can do all the copy and checks to make sure it's looking in the correct places but just not the findstr section.

Any idea of what to do to understand would be fantastic

1
  • is the file single line? Commented Sep 9, 2014 at 12:47

2 Answers 2

1
@echo off
set "start_file=start.txt"
for /f tokens^=5^ delims^=\^" %%# in ('type "%start_file%"^|find /i "..\posdata"') do set "xml_file=%%#"

echo %xml_file%

Your question is a little bit unclear.Is this the only line in the file? Is this the exact content? How can I recognize the line with the file?

The script above will work in case there's only one line wwith "..\postdata" string and the content is exact as described in question.

Edit Covering the both cases:

@echo off
setlocal 
set "start_file=start.txt"
set "xml_file="
for /f tokens^=5^ delims^=\^" %%# in ('type "%start_file%"^|find /i "..\posdata"^|find /i /v "-storedbpath"') do set "xml_file=%%#"
if not defined xml_file (

    for /f "usebackq tokens=9" %%# in ("%start_file%") do (
        set "xml_file=%%~#"
    )
)
echo %xml_file%
Sign up to request clarification or add additional context in comments.

6 Comments

Sorry, wasn't sure what would be needed. That is the only line in the file at all and it's exactly like that. I'll have a wee play now. Thank you in advance
Okay, that worked like an absolute charm until I just came across 1 file out of 20 that also holds the following line ..\bin\JavaBin | javaw -jar np6-app.jar -storedbpath=..\..\posdata\ -localfile="_8001_pos-db.xml" which causes a double output of xml_file=filename.xml followed by xml_file=posdata
Will be able to chrck it after 2hours @Sept .now Im writing from my phone.
@Sept - the line that causes problems looks pretty different from this one in the question. I can differ the both cases with IF , but if there are more different cases it again will cause troubles. I will edit my answer , but be prepared.Hope you have only these two cases.
Perfect. Worked like a charm.
|
0

Text this:

for /f "usebackq tokens=4" %%a in ("start.txt") do echo %%~nxa

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.