Substitute characters command

G

Guest

Hello everybody!

I would like a bat-file that prints a directory tree to a file and then
replaces some wrong characters in the file.

Thanks to this forum I've learned how to get a directory tree by using the
command
tree
and how to make a file of it
tree > myfile.txt
Then I got strange characters so I used ASCII instead
tree /A > myfile.txt

But I still get strange some characters. Is there a "search and replace"
command? I want to use
Ã¥
ä
ö
but instead I get
†
„
â€

Thanks for any help!
 
G

Guest

I will suggest to open this file in Microsoft Word to accomplish this task
because Word has many special feature in Find and Replace command. Click
Replace from Edit menu and then click More button and make a check mark on
Wild Card then enter the strings in Find and Replace.

You can also try GUI Program for the same.

http://www.karenware.com/powertools/ptdirprn.asp

Hope this help, let us know!
 
A

Ayush

Replied to [Dudute]s message :
Hello everybody!

I would like a bat-file that prints a directory tree to a file and then
replaces some wrong characters in the file.

Thanks to this forum I've learned how to get a directory tree by using the
command
tree
and how to make a file of it
tree > myfile.txt
Then I got strange characters so I used ASCII instead
tree /A > myfile.txt

But I still get strange some characters. Is there a "search and replace"
command? I want to use
Ã¥
ä
ö
but instead I get
†
„
â€

Thanks for any help!


You can use this VBs (i am not good at bat scripting) :

This scripts accepts two arguments :
1st : filename , 2nd : replace character:replace with char.|replace
character:replace with char.|etc.etc/

example :
ScriptPath.vbs "FilePath.txt" "†:Ã¥|„:ä|â€:ö"

'- - - - - - - - - - - - - - - - - -
Set args = WScript.Arguments
If args.Count <= 1 Then WScript.Quit

fN = args(0) : replChrs = split(args(1),"|")

txt = openFile(1)

for arrIx=0 to UBound(replChrs)
repW = split(replChrs(arrIx),":")
txt = replace(txt,repW(0),repW(1))
Next

openFile 2

Function openFile(readWrite)
set fso = CreateObject("Scripting.FileSystemObject")
set txtStrm = fso.OpenTextFile(fN, readWrite)
if readWrite=1 then openFile=txtStrm.ReadAll else txtStrm.Write(txt)
txtStrm.Close
End Function
'- - - - - - - - - - - - - - - - - -
 
A

Ayush

Replied to [Ayush]s message :

Use this :
'- - - - - - - - - - - - - - - - - -
Set args = WScript.Arguments
If args.Count <= 1 Then WScript.Quit
set fso = CreateObject("Scripting.FileSystemObject")

fN = args(0) : replChrs = split(args(1),"|")
txt = openFile(1)

for arrIx=0 to UBound(replChrs)
repW = split(replChrs(arrIx),":")
txt = replace(txt,repW(0),repW(1))
Next

openFile 2

Function openFile(readWrite)
set txtStrm = fso.OpenTextFile(fN, readWrite)
if readWrite=1 then openFile=txtStrm.ReadAll else txtStrm.Write(txt)
txtStrm.Close
End Function
'- - - - - - - - - - - - - - - - - -



Not this:
 
K

Ken Blake, MVP

RajKohli said:
I will suggest to open this file in Microsoft Word to accomplish this
task because Word has many special feature in Find and Replace
command. Click Replace from Edit menu and then click More button and
make a check mark on Wild Card then enter the strings in Find and
Replace.


Anybody who use any word processor to edit a text file needs to be aware
that if you simply save the file, it will then be in the word propcessor's
proprietary format and not in text format any longer.

That's why using a word processor as a text editor is normally a poor idea.
Yesm you can do it if you always remember to do a "Save as" instead of a
"Save," and change the format to txt, but it's easy to forget.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top