Page 1 of 1

I need some help Please

Posted: 23 Jan 2019 20:08
by GreyFalcon70
This is a script I found that works Great cept one thing. Can someone help me change the Underscore to an open space or whitespace i think it is called????

Code: Select all

@echo off
setlocal EnableDelayedExpansion
:: remove variables starting $ 
For %%b IN ($) DO FOR  /F "delims==" %%a In ('set %%b 2^>Nul') DO SET "%%a="
FOR %%a IN (0 1 2 3 4 5 6 7 8 9 a b c d e f) DO (
 FOR %%b IN (0 1 2 3 4 5 6 7 8 9 a b c d e f) DO (
  SET "$%%a%%b=%%%%a%%b"
 )
)
for /f "delims=" %%I in ('dir /b /a-d^| find "%%"') do (
 SET "var1=%%I"
 FOR /f "tokens=2delims==" %%x IN ('set $') DO SET "var1=!var1:%%x=_"!"
 IF "%%I" neq "!var1!" REN "%%I" "!var1!"
)
GOTO :EOF

Re: I need some help Please

Posted: 23 Jan 2019 21:09
by ShadowThief

Code: Select all

FOR /f "tokens=2delims==" %%x IN ('set $') DO SET "var1=!var1:%%x= "!"
Note that I haven't actually tested this, I just changed what is literally the only underscore in the entire code to a regular space.

Re: I need some help Please

Posted: 23 Jan 2019 21:48
by GreyFalcon70
:D I tried that already it simply does nothing to the filenames.

Re: I need some help Please

Posted: 24 Jan 2019 06:01
by Ed Dyreen
$00=%00
$01=%01
....

There must exist some files in local directory that have char '%' in their filename.
Only then for /f "delims=" %%I in ('dir /b /a-d^| find "%%"') do (
will enumerate.

SET "var1=%%I"
var1=%00filename.extension. I added %00 to get a match later in your code.

FOR /f "tokens=2delims==" %%x IN ('set $') DO SET "var1=!var1:%%x=_"!"
so it does
set var1=!var1:%00=_"!
set var1=!var1:%01=_"!
etcetera...

that results in var1=_"filename.extension

IF "%%I" neq "!var1!" REN "%%I" "!var1!"
)
GOTO :EOF

It seems that there must exist some file named %[0-9,a-f][0-9,a-f][.*] for this script to work.

it try to replace %[0-9,a-f][0-9,a-f][.*] for all files with _"[.*]

the assignment will work but now REN fails because the name is not a valid filename, filenames cannot contain char '"'

I believe it was supposed to be SET "var1=!var1:%%x=_!" or if you want space SET "var1=!var1:%%x= !"

Add the command @echo on at the top of your batch to see what cmd is actually doing and use the Set command whenever in doubt, just as this script does. The naked Set command will list all "normal" variables and their definitions.