I need some help Please

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
GreyFalcon70
Posts: 2
Joined: 23 Jan 2019 18:39

I need some help Please

#1 Post by GreyFalcon70 » 23 Jan 2019 20:08

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

ShadowThief
Expert
Posts: 1160
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: I need some help Please

#2 Post by ShadowThief » 23 Jan 2019 21:09

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.

GreyFalcon70
Posts: 2
Joined: 23 Jan 2019 18:39

Re: I need some help Please

#3 Post by GreyFalcon70 » 23 Jan 2019 21:48

:D I tried that already it simply does nothing to the filenames.

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: I need some help Please

#4 Post by Ed Dyreen » 24 Jan 2019 06:01

$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.

Post Reply