Computing.Net > Forums > Programming > del text in txt file except dir

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

del text in txt file except dir

Reply to Message Icon

Name: damonp
Date: November 5, 2008 at 12:25:59 Pacific
OS: XP
CPU/Ram: 2GB
Product: Self Built
Comment:

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 VB

Damon



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: November 5, 2008 at 12:52:38 Pacific
Reply:

It might help to post the html.


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 2
Name: damonp
Date: November 6, 2008 at 06:41:26 Pacific
Reply:

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


0

Response Number 3
Name: Mechanix2Go
Date: November 7, 2008 at 00:57:25 Pacific
Reply:

:: get path from html

@echo off > ###
setLocal EnableDelayedExpansion

find /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 :sub1

goto :eof


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 4
Name: damonp
Date: November 7, 2008 at 20:14:49 Pacific
Reply:

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 EnableDelayedExpansion

find /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 :sub1

goto :eof

Damon


0

Response Number 5
Name: Mechanix2Go
Date: November 8, 2008 at 08:01:57 Pacific
Reply:

@echo off > ###
setLocal EnableDelayedExpansion

find /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 :sub1

goto :eof


=====================================
If at first you don't succeed, you're about average.

M2


0

Related Posts

See More



Response Number 6
Name: damonp
Date: November 8, 2008 at 17:24:23 Pacific
Reply:

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


0

Response Number 7
Name: Mechanix2Go
Date: November 9, 2008 at 01:54:11 Pacific
Reply:

I goofed.

===================================
@echo off > ###
setLocal EnableDelayedExpansion

find /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 :sub1

goto :eof


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 8
Name: damonp
Date: November 9, 2008 at 09:43:23 Pacific
Reply:

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 EnableDelayedExpansion

find /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 :sub1

goto :eof
---------------------

Mechanix2go,
I also wanted to tell you thanks for taking the time to help me with this.

Damon


0

Response Number 9
Name: Mechanix2Go
Date: November 10, 2008 at 04:27:49 Pacific
Reply:

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


0

Response Number 10
Name: damonp
Date: November 10, 2008 at 06:24:43 Pacific
Reply:

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


0

Response Number 11
Name: Mechanix2Go
Date: November 10, 2008 at 06:28:48 Pacific
Reply:

First run it from a CMD prompt.


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 12
Name: damonp
Date: November 25, 2008 at 12:41:16 Pacific
Reply:

Thanks Mechanix2Go, once i ran(call) it from another bat file it worked great.

thanks,

Damon


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: del text in txt file except dir

add or replace text in .txt file www.computing.net/answers/programming/add-or-replace-text-in-txt-file/18121.html

Delete 1st 4 lines & last 8 Lines in TXT File www.computing.net/answers/programming/delete-1st-4-lines-last-8-lines-in-txt-file/19676.html

Find and Replace text in Batch File www.computing.net/answers/programming/find-and-replace-text-in-batch-file/12413.html