Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am trying to create a batch file that will complete the action I need. It will always run in WinXP.
I have been researching this for a couple of weeks, and I have not found the solution.*** First problem is that I need to save a .xml file to text file with the wordwrap on. coping the file is easy but it copies everything in one line. I can manually turn on word wrap and its fine, but I need it to automatically save to a txt with wordwrap.
*** Second, I need to be able to locate and assign a dir within the txt file to a varible. I have thought that if I butcher the new text file and have the batch file del everything but the dir that I need then I will be in business. the only problem is that I can del out lines of text(after I manually enable wordwrap in notepad) but I have not been able to del the begining and end of the line and keep the dir information that I need to set as a var. The last half of the dir information will always be changing, so it will always begin with "C:\program files\program" (I will be setting this bat file to automatically run before the program is launched.)
If anyone can help. I want to use a batch file but I think I may have to go VBDamon

It might help to post the html.
=====================================
If at first you don't succeed, you're about average.M2

here is what I have:
this is the file that has been copied as a text file. When it is copied the wordwrap is not on. so all this code is on one line.<?xml version="1.0" encoding="Windows-1252"?><!--Application Defaults--><appdefaults><lastuserid>user11</lastuserid><movetodir>c:\program files\program\folder1\A\Reports</movetodir><movefromdir>c:\program files\program\folder1\A\Rejected</movefromdir></appdefaults>
the ONLY part of this that i need to remain is c:\program files\program\folder1\A\Reports
is there a way that i can use a batch file to del everything but this line? Keeping in mind that \folder1\a\rejected will always be changing on this line. the only constant will be c:\program files\program\Wordwrap is not an important issue. I just know that if i could enable it from a batch file then
<movetodir>c:\program files\program\folder1\A\Reports</movetodir>
this would be own its own line. May make it eaier to extract out the dir alone.
thanks
Damon

:: get path from html
@echo off > ###
setLocal EnableDelayedExpansionfind /i "c:\program" < myhtml > ##
for /f "tokens=* delims= " %%x in (##) do (
set str=%%x
call :sub1
)set /p myvar=<###
echo myvar is set to: !myvar!
del ##?goto :eof
:sub1
for /f "tokens=1* delims=<>" %%a in ("!str!") do (
echo %%a | find /i "c:\program files" >> ###
set str=%%b
)
if not "!str!"=="" goto :sub1goto :eof
=====================================
If at first you don't succeed, you're about average.M2

I may not be using the code correctly.
GetPath.html ----- is the file that has the directory that I am trying to obtain
GetPath.txt ---- Is where I want the obtained dir c:\program files\program\folder1\A\Reports copied to, with nothing else in this file.
I tried the below with the modifications, I think i may be changing the wrong thing.
:: get path from html@echo off > ###
setLocal EnableDelayedExpansionfind /i "c:\program" < GetPath.html > GetPath.txt
for /f "tokens=* delims= " %%x in (GetPath.txt) do (
set str=%%x
call :sub1
)set /p myvar=<###
echo myvar is set to: !myvar!
del ##?goto :eof
:sub1
for /f "tokens=1* delims=<>" %%a in ("!str!") do (
echo %%a | find /i "c:\program files" >> ###
set str=%%b
)
if not "!str!"=="" goto :sub1goto :eof
Damon

@echo off > ###
setLocal EnableDelayedExpansionfind /i "c:\program" < GetPath.html > GetPath.txt
for /f "tokens=* delims= " %%x in (GetPath.txt) do (
set str=%%x
call :sub1
)set /p myvar=<###
echo !myvar! > GetPath.txt
del ##?goto :eof
:sub1
for /f "tokens=1* delims=<>" %%a in ("!str!") do (
echo %%a | find /i "c:\program files" >> ###
set str=%%b
)
if not "!str!"=="" goto :sub1goto :eof
=====================================
If at first you don't succeed, you're about average.M2

When I run the script, copy and pasted it.
the getpath.txt displays the output nothing more.
ECHO is off.
Is there something I may have missed?
Damon

I goofed.
===================================
@echo off > ###
setLocal EnableDelayedExpansionfind /i "c:\program" < GetPath.html > GetPath.txt
for /f "tokens=* delims= " %%x in (GetPath.txt) do (
set str=%%x
call :sub1
)set /p myvar=<###
echo !myvar!> GetPath.txt
del ##?goto :eof
:sub1
for /f "tokens=1* delims=<>" %%a in ("!str!") do (
echo %%a | find /i "c:\program" >> ###
set str=%%b
)
if not "!str!"=="" goto :sub1goto :eof
=====================================
If at first you don't succeed, you're about average.M2

I tried just a straigt cut and paste and I get the same thing as before.
Echo is off.
I tried putting Pause in certain spots and opening the GetPath.txt file inbetween pauses then closing it making sure that it would be able to write to it. when I run the batch file I get 8 pauses, I realize that this happens because of the goto cmd, as I check the GetPath.txt it will display the GetPath.html data in it, in one long line. on the 8th time of pause once I hit the button to continue it will basically create a new GetPath.txt and the only thing in it is
Echo is off.
this is where i put in the pauses, I copied from my bat file.
--------------------
@echo off > ###
setLocal EnableDelayedExpansionfind /i "c:\program" < GetPath.html > GetPath.txt
for /f "tokens=* delims= " %%x in (GetPath.txt) do (
set str=%%x
call :sub1
)pause
set /p myvar=<###
echo !myvar!> GetPath.txt
del ##?goto :eof
:sub1
pause
for /f "tokens=1* delims=<>" %%a in ("!str!") do (
echo %%a | find /i "c:\program" >> ###
set str=%%b
)
if not "!str!"=="" goto :sub1goto :eof
---------------------Mechanix2go,
I also wanted to tell you thanks for taking the time to help me with this.Damon

I think I've lost the plot.
Are you runing this from a CMD prompt? [ie NOT clicking on it.]
Is the batch in the same directory as the GetPath.html?
=====================================
If at first you don't succeed, you're about average.M2

I am running it by double clicking the GetPath.bat file that this code has been copied into. all files are in the same dir/folder. would adding the entire path help my problem?
Damon

First run it from a CMD prompt.
=====================================
If at first you don't succeed, you're about average.M2

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |