Can the replace function of set differ in lower case and
upper case letters?
I simplified the problem in that lines:
===================================================
setlocal enabledelayedexpansion
@echo off
echo ae>listing.txt
echo Ae>>listing.txt
FOR /F "tokens=*" %%a in ('type listing.txt') do (
set name=%%a
set name=!name:ae=_lower_!
set name=!name:Ae=_upper_!
echo !name!
)
pause
===================================================
I get the output
_lower_
_lower_
but i expected the output
_lower_
_upper_
What can i do to teach the set-replace-funcion to differ in
upper case and lower case letters?
Greetings
Carsten
Carsten, what you are asking is convoluted, but can be done.
I susppect that the real task can be done a different way if you explain
it.
While the statemment "if %name%==Carsten" is case-sensitive, string
substitution such as "set name=%name:ae=_lower_%" is not. I suggest you use
a pure or hybrid VB Script solution - it has inbuilt upper/lower case
functions.
As foxidrive stated, I'm sure that you can do the task a different way.
::----- START Example.cmd -----
@ECHO OFF & SETLOCAL ENABLEEXTENSIONS
>_$LST.LOG (ECHO ae & ECHO Ae)
FOR /F %%# IN (_$LST.LOG) DO CALL :_ %%#
DEL _$LST.LOG & PAUSE & GOTO :EOF
:_
(SET NAME=%1)
IF %NAME:~,1% EQU a (SET NAME=%NAME:ae=_lower_%) ELSE (
IF %NAME:~,1% EQU A SET "NAME=%NAME:Ae=_upper_%")
ECHO %NAME%
::------ END Example.cmd ------
Thank You all for Your ideas.
As i learned, the string substitution can't differ in upper case letters and lower case letters. Ok.
My task is to replace filenames with the german umlaut substitutes (ae oe ue) back in umlauts (ᅵ ᅵ ᅵ). You may laugh at my planned
way, but i plan to do it with a combined batch and Word-script.
One txt file contains the original filenames.
Another txt file is identical to that at the beginning.
Then i do several replace-works in that second file with
a Word-script.
After that i do a line-per-line check with the EQU or the ==
function. If it differs, the batch creates a line in the
rename-batch.
That final pure rename-batch will be checked several times
by hand/eyes and then be executed.
In past, my batch works fine with replace several unwanted
chars (like multiple spaces, etc.)
The problem is to differ in several language problems.
There are english words which looks like german mutation
substitution, but aren't: blue, tongue, true, etc.
That words are collected by me and put in the rename
batch. There are several german words with the mutation
substitution, but there it is correct (like Konsequenz).
My secound option is a tool to batch-rename the files.
A quick internet search brings me up several tools.
I prefer the way with Word-script, but i will see.
Here i present the actual rename-order:
=======================================
Search="ae" Replace="ᅵ"
Search="oe" Replace="ᅵ"
Search="ue" Replace="ᅵ"
Search="Ae" Replace="ᅵ"
Search="Oe" Replace="ᅵ"
Search="Ue" Replace="ᅵ"
Search="Tᅵk" Replace="Taek"
Search="Blᅵ" Replace="Blue"
Search="luet" Replace="lᅵt"
Search="lueh" Replace="lᅵh"
Search="luem" Replace="lᅵm"
Search="Blᅵs" Replace="Blues"
Search="dᅵll" Replace="duell"
Search="Dᅵll" Replace="Duell"
Search="Crusᅵ" Replace="Crusoe"
Search="eᅵ" Replace="eue"
Search="Trᅵ " Replace="True "
Search="Michᅵl" Replace="Michael"
Search="Reggᅵ" Replace="Reggae"
Search="aᅵ" Replace="aue"
Search="Aᅵ" Replace="Aue"
Search="qᅵ" Replace="que"
Search="Qᅵ" Replace="Que"
=======================================
It isn't complete yet. I try and add several lines.
Maybe the whole project can't be done automatically.
The future will show the result.
Greetings
Carsten
The VB Script below could easily do the job. It relies on you creating a
dictionary file of the following form:
ae �
oe �
Regg� Reggae
etc.
The words must be separated by a single space.
const sInput = "d:\Input.txt"
Const sOutput = "d:\Output.txt"
Const sDict = "d:\Dict.txt"
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oInput = oFSO.OpenTextFile(sInput)
Set oDict = oFSO.OpenTextFile(sDict)
sData = oInput.ReadAll
aDict = Split(oDict.ReadAll, VbCrLf)
For i = 0 To UBound(aDict) - 1
aWord = Split(aDict(i))
sData = Replace(sData, aWord(0), aWord(1))
Next
Set oOutput = oFSO.CreateTextFile(sOutput, True)
oOutput.Write sData
oOutput.Close
>
> The VB Script below could easily do the job. It relies on you creating a dictionary file of the following form:
> ae ᅵ
> oe ᅵ
> Reggᅵ Reggae
> etc.
> The words must be separated by a single space.
>
> const sInput = "d:\Input.txt"
> Const sOutput = "d:\Output.txt"
> Const sDict = "d:\Dict.txt"
> Set oFSO = CreateObject("Scripting.FileSystemObject")
> Set oInput = oFSO.OpenTextFile(sInput)
> Set oDict = oFSO.OpenTextFile(sDict)
>
> sData = oInput.ReadAll
> aDict = Split(oDict.ReadAll, VbCrLf)
>
> For i = 0 To UBound(aDict) - 1
> aWord = Split(aDict(i))
> sData = Replace(sData, aWord(0), aWord(1))
> Next
>
> Set oOutput = oFSO.CreateTextFile(sOutput, True)
> oOutput.Write sData
> oOutput.Close
>
Hello again.
After a month, i met a problem in that script.
Is it possible: after line 32 in the Dict.txt isn't executed
Have i to do some DIM for variables, maybe?
If i have to do so: how should i do so?
Greetings
Carsten
>
>"Pegasus" <I....@fly.com.oz> schrieb im Newsbeitrag news:4ab114c2$0$150$fb62...@newsspool.solnet.ch...
>>
>> The VB Script below could easily do the job. >
>After a month, i met a problem in that script.
Why is it that you didn't return to thank Pegasus for his code, if you have
been using it for a month?
Seeing that fewer than 10% of all posters take the time to post a brief
"Thank you" note, Carsten is in excellent company. Yet I sometimes wonder
what makes posters think that a "TIA" is sufficient acknowledgment for a
piece of code that can span 20 or 30 lines of code, that is usually debugged
and tested by the respondent and that is based on a lot of technical
expertise. It seems I'm not the only one who is puzzled.
I guess they don't realize that we get paid in "atta boys" ;-)
(I there an equivalent of "atta boy" in German?)
I guess we need to be satisfied with the understanding that we have
added something to the harmony of the universe, ;;-))
_____________________
Tom Lavedas
Maybe "Wir tun's f�r ein Butterbrot".
No one would say "Heil dir!" since the days of the Third Reich.
"Gl�ck auf!" is very old-fashioned and not really appropriate in this
context.
"Bravo, mein Junge, gut gemacht!" comes closest to "atta boy!".
How did we get onto this linguistic tangent? Have we lost the OP?
I didn't using it a whole month - it resides on my desktop
and is tested and executed in free minutes (there aren't many).
As You can search, I ofter answer questions of other people.
Sometimes my answers helps a bit, sometimes not.
I never expected a "thank you" for my own posts.
Some people shouts because of useless lines in postings and
bandwith using. Other people feels "kicked on the tail"
(in my hometown is it called so and i translated it) about the
fact of useless thank posts. They want to keep the overview of
the postings.
Sometimes i didn't know what correctly to do.
Ok, i'm sorry of forgetting a thank you.
I put it in big letters:
THANK YOU
Now, i solved my problem with my own capabilities.
The batch looks rather funny, but as i have read somewhere:
if a procedure looks funny, but works as expected,
it isn't funny.
Maybe someone can use any part of my solution:
==========begin file "mutations1.vbs"==========
const sInput = "d:\Input.txt"
Const sOutput = "d:\Output1.txt"
Const sDict = "d:\Dict1.txt"
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oInput = oFSO.OpenTextFile(sInput)
Set oDict = oFSO.OpenTextFile(sDict)
sData = oInput.ReadAll
aDict = Split(oDict.ReadAll, VbCrLf)
For i = 0 To UBound(aDict) - 1
aWord = Split(aDict(i))
sData = Replace(sData, aWord(0), aWord(1))
Next
Set oOutput = oFSO.CreateTextFile(sOutput, True)
oOutput.Write sData
oOutput.Close
==========end file "mutations1.vbs"==========
==========begin file "mutations2.vbs"==========
const sInput = "d:\Output1.txt"
Const sOutput = "d:\Output2.txt"
Const sDict = "d:\dict2.txt"
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oInput = oFSO.OpenTextFile(sInput)
Set oDict = oFSO.OpenTextFile(sDict)
sData = oInput.ReadAll
aDict = Split(oDict.ReadAll, VbCrLf)
For i = 0 To UBound(aDict) - 1
aWord = Split(aDict(i))
sData = Replace(sData, aWord(0), aWord(1))
Next
Set oOutput = oFSO.CreateTextFile(sOutput, True)
oOutput.Write sData
oOutput.Close
==========end file "mutations2.vbs"==========
==========begin file "mutations.bat"==========
@echo off
setlocal enabledelayedexpansion
dir /A-D /s /b f:\ | findstr "ae oe ue Ae Oe Ue">d:\input.txt
echo.>--re-naming.bat
pushd "%~dp0"
cd
copy dict?.txt d:\
cscript mutations1.vbs
cscript mutations2.vbs
del D:\output1.txt D:\dict?.txt
set counter=0
for /f "tokens=*" %%a in ('type d:\input.txt') do call :input %%a
set counter=0
for /f "tokens=*" %%a in ('type d:\output2.txt') do call :output %%a
for /L %%a in (1,1,%counter%) do call :comparing %%a
goto :EOF
:input
set /A counter=%counter%+1
set input%counter%=%*
goto :EOF
:output
set /A counter=%counter%+1
set output%counter%=%*
goto :EOF
:comparing
set counter=%1
set input=!input%counter%!
set output=!output%counter%!
if NOT "%input%"=="%output%" (
for /f "tokens=3,4,5,6,7,8,9,10,11,12* delims=\" %%a in ('echo %output%') do(
if "%%j"=="" set new_name=%%i
if "%%i"=="" set new_name=%%h
if "%%h"=="" set new_name=%%g
if "%%g"=="" set new_name=%%f
if "%%f"=="" set new_name=%%e
if "%%e"=="" set new_name=%%d
if "%%d"=="" set new_name=%%c
if "%%c"=="" set new_name=%%b
if "%%b"=="" set new_name=%%a
)
echo ren "%input%" "!new_name!">>--re-naming.bat
)
echo pause>>--re-naming.bat
==========end file "mutations.bat"==========
==========begin file "dict1.txt"==========
ae ä
oe ö
ue ü
Ae Ä
Oe Ö
Ue Ü
eü eue
Täk Taek
Blü Blue
luet lüt
lueh lüh
luem lüm
Blüs Blues
düll duell
Düll Duell
Crusö Crusoe
Trü True
Truemmer Trümmer
Reggä Reggae
aü aue
Aü Aue
qü que
Qü Que
gös goes
Äon Aeon
Jö Joe
Revü Revue
Tongü Tongue
tongü tongue
Clü Clue
clü clue
==========end file "dict1.txt"==========
==========begin file "dict2.txt"==========
Michäl Michael
==========end file "dict2.txt"==========
Please take caution:
always edit the dict.txt files with an ANSI editor.
The cmd-box internal command "edit" did well for me.
I think, the mutations have to be ANSI for filenames.
I didn't take care of that fact in my first testings.
So the filenames have strange chars like the "high 2",
the sign for "squared".
I build an addition to re-re-name that strange chars
back to mutations. That isn't easy to post because of
mutation translation in several charsets of newsreaders.
===start addition======================
set new_name=!new_name:õ=ä!
set new_name=!new_name:÷=ö!
set new_name=!new_name:³=ü!
set new_name=!new_name:─=Ä!
set new_name=!new_name:Í=Ö!
set new_name=!new_name:▄=Ü!
===end addition========================
If i find a way to encode that lines in a way
so every newsreader can show it correctly, i
put it here.
How should the addition looks like?
The first char after the double-point is the
char, a dir command shows for the wrong
mutation. After the last equal sign there
have to be a real mutation.
The dict.txt files musn't exceed 32 lines.
Words after line 32 (or 33, i don't tested it exactly)
aren't replaced, they are ignored.
My little knowledge in VBS programming let me think,
the line
For i = 0 To UBound(aDict) - 1
is the limit. I don't know exactly.
I replaced everything behind the "To" with a number,
starting with 30. As i reached 32 or 33 i gets an
VBS error. Maybe someone can fix that problem.
Then, there is only on big dict.txt file needed.
Always check the created re-naming.bat carefully.
It isn't executed automatically. It have to be
started by the user.
So You can spend time to check that batch. Many files
are renamed wrong my first times. So i have to trim
the renaming rules in the dict.txt files.
I'm sure there are plenty of exceptions i forgot.
I collected words and names and created plenty of empty
files in temp folders for testing purposes.
But i'm sure i haven't every possible word and name as
a filename on the harddisk...
All my renaming-batch-files have to be in the same folder.
The batch is copying several files and creating others.
After success, it creates a batch called:
--re-naming.bat
That is the batch to be checked with human eyes.
Maybe someone will take something out of my procedure.
Thank You so far
Greetings
Carsten
"Carsten Beckermann" <derd...@web.de> wrote in message
news:hbcavg$vfl$00$1...@news.t-online.com...
>
> "foxidrive" <got...@woohoo.invalid> schrieb im Newsbeitrag
> news:0gmgd5l3tkai1v0mt...@4ax.com...
>> On Fri, 16 Oct 2009 13:20:56 +0200, "Carsten Beckermann"
>> <derd...@web.de>
>> wrote:
>>
>>>
>>>"Pegasus" <I....@fly.com.oz> schrieb im Newsbeitrag
>>>news:4ab114c2$0$150$fb62...@newsspool.solnet.ch...
>>>>
>>>> The VB Script below could easily do the job. >
>>
>>>After a month, i met a problem in that script.
>>
>> Why is it that you didn't return to thank Pegasus for his code, if you
>> have
>> been using it for a month?
>>
>
> I didn't using it a whole month - it resides on my desktop
> and is tested and executed in free minutes (there aren't many).
>
> As You can search, I ofter answer questions of other people.
> Sometimes my answers helps a bit, sometimes not.
> I never expected a "thank you" for my own posts.
*** I don't expect it either but I always say "Thank you" when
*** someone helps me, be it a friend or a stranger. It's one of
*** my principles.
> Some people shouts because of useless lines in postings and
> bandwith using. Other people feels "kicked on the tail"
> (in my hometown is it called so and i translated it) about the
> fact of useless thank posts. They want to keep the overview of
> the postings.
*** I have never ever seen anyone complain about a "Thank you"
*** response. Can you point me to a thread where someone got
*** his backside kicked for saying Thank You?.
> Sometimes i didn't know what correctly to do.
> Ok, i'm sorry of forgetting a thank you.
>
> I put it in big letters:
> THANK YOU
*** Thanks for the feedback.
> Now, i solved my problem with my own capabilities.
> The batch looks rather funny, but as i have read somewhere:
> if a procedure looks funny, but works as expected,
> it isn't funny.
*** Not really. In my opinion a good program is one that meets
*** these requirements:
*** - It works
*** - It is robust
*** - It is well structured
*** - It is elegant
*** - It is maintainable
> ae �
> oe �
> ue �
> Ae �
> Oe �
> Ue �
> e� eue
> T�k Taek
> Bl� Blue
> luet l�t
> lueh l�h
> luem l�m
> Bl�s Blues
> d�ll duell
> D�ll Duell
> Crus� Crusoe
> Tr� True
> Truemmer Tr�mmer
> Regg� Reggae
> a� aue
> A� Aue
> q� que
> Q� Que
> g�s goes
> �on Aeon
> J� Joe
> Rev� Revue
> Tong� Tongue
> tong� tongue
> Cl� Clue
> cl� clue
> ==========end file "dict1.txt"==========
>
>
> ==========begin file "dict2.txt"==========
> Mich�l Michael
> ==========end file "dict2.txt"==========
>
>
>
> Please take caution:
> always edit the dict.txt files with an ANSI editor.
> The cmd-box internal command "edit" did well for me.
*** "Edit" is a legacy editor. I recommend you use notepad.exe
*** as a text editor, if only so that you can use standard
*** cut & paste facilities.
> I think, the mutations have to be ANSI for filenames.
> I didn't take care of that fact in my first testings.
> So the filenames have strange chars like the "high 2",
> the sign for "squared".
>
> I build an addition to re-re-name that strange chars
> back to mutations. That isn't easy to post because of
> mutation translation in several charsets of newsreaders.
>
> ===start addition======================
> set new_name=!new_name:�=�!
> set new_name=!new_name:�=�!
> set new_name=!new_name:�=�!
> set new_name=!new_name:?=�!
> set new_name=!new_name:�=�!
> set new_name=!new_name:?=�!
> ===end addition========================
>
> If i find a way to encode that lines in a way
> so every newsreader can show it correctly, i
> put it here.
>
> How should the addition looks like?
> The first char after the double-point is the
> char, a dir command shows for the wrong
> mutation. After the last equal sign there
> have to be a real mutation.
>
> The dict.txt files musn't exceed 32 lines.
> Words after line 32 (or 33, i don't tested it exactly)
> aren't replaced, they are ignored.
> My little knowledge in VBS programming let me think,
> the line
> For i = 0 To UBound(aDict) - 1
> is the limit. I don't know exactly.
*** This is incorrect. There is no limit to the size of the
*** dictionary file, other than speed of processing.
*** I just tested your VB Script with a 128-line dictionary
*** file - no problem at all. If you have a problem then you
*** should post your input file, your dictionary file and the
*** error message you see.
> I replaced everything behind the "To" with a number,
> starting with 30. As i reached 32 or 33 i gets an
> VBS error. Maybe someone can fix that problem.
*** You must leave the line
*** For i = 0 To UBound(aDict) - 1
*** as it is. It adjusts itself automatically to the size
*** of your dictionary.
> Then, there is only on big dict.txt file needed.
>
> Always check the created re-naming.bat carefully.
> It isn't executed automatically. It have to be
> started by the user.
>
> So You can spend time to check that batch. Many files
> are renamed wrong my first times. So i have to trim
> the renaming rules in the dict.txt files.
>
> I'm sure there are plenty of exceptions i forgot.
> I collected words and names and created plenty of empty
> files in temp folders for testing purposes.
> But i'm sure i haven't every possible word and name as
> a filename on the harddisk...
>
> All my renaming-batch-files have to be in the same folder.
> The batch is copying several files and creating others.
>
> After success, it creates a batch called:
> --re-naming.bat
>
> That is the batch to be checked with human eyes.
>
> Maybe someone will take something out of my procedure.
>
> Thank You so far
> Greetings
> Carsten
*** Your initial post implied that you needed to translate
*** certain strings in a text file with different strings. It now
*** emerges that you wish to rename a number of files that
*** have German umlaute in their names. If you had stated
*** this in the first place then someone might have suggested
*** a solution based on a single VB Script, which would be
*** more elegant and much easier to maintain than your
*** current solution that relies on two script and one batch
*** file.