Using forfiles with Windows 10 vs Win 7 question

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Jer
Posts: 177
Joined: 23 Nov 2014 17:13
Location: California USA

Using forfiles with Windows 10 vs Win 7 question

#1 Post by Jer » 28 Feb 2017 22:44

The code below is part of a project the includes using any "friendly" DOS character
in the borders of a box. This is batch only, not hybrid or 3rd party tools.
The project was going well until I tried it on my new Window 10 PC. My forfiles
method of capturing DOS characters into variables has a problem with the lower
ascii codes and displays only a box with a question mark.

In my project I am eliminating certain characters that might be unfriendly, and those
show in the ascii table as blank.

Does anyone have any solution to this issue after upgrading to Windows 10?
Thanks.

Code: Select all

@Echo Off

call :asciiTable
goto :eof

:asciiTable
 rem display a table of ascii characters and codes in the range 1-255.
 rem problem characters will have a code # but no character and not be available as a border char.
 setlocal EnableDelayedExpansion

 Call :makeHexString hString
 Set "i=1"
 For %%a In (%hString%) Do Set "hx[!i!]=0x%%a" & Set /A "i+=1"
 Set "idx=0" & Set "idx2=1"

 For /L %%n In (1,1,15) Do (
    For /L %%r In (1,1,17) Do Set /A "i%%r=%%r+!idx!"
    Call Set "str=%%hx[!i1!]%% %%hx[!i2!]%% %%hx[!i3!]%% %%hx[!i4!]%% %%hx[!i5!]%% %%hx[!i6!]%% %%hx[!i7!]%%"
    Call Set "str=!str! %%hx[!i8!]%% %%hx[!i9!]%% %%hx[!i10!]%% %%hx[!i11!]%% %%hx[!i12!]%% %%hx[!i13!]%% %%hx[!i14!]%%"
    Call Set "str=!str! %%hx[!i15!]%% %%hx[!i16!]%% %%hx[!i17!]%%"

    For /F "tokens=1-17" %%a In (
      'forfiles /p "%~dp0." /m "%~nx0" /c "cmd /c echo(!str!"') Do (
         Set "char[!i1!]=%%a" & Set "char[!i2!]=%%b" & Set "char[!i3!]=%%c" & Set "char[!i4!]=%%d" & Set "char[!i5!]=%%e"
         Set "char[!i6!]=%%f" & Set "char[!i7!]=%%g" & Set "char[!i8!]=%%h" & Set "char[!i9!]=%%i" & Set "char[!i10!]=%%j"
         Set "char[!i11!]=%%k" & Set "char[!i12!]=%%l" & Set "char[!i13!]=%%m" & Set "char[!i14!]=%%n" & Set "char[!i15!]=%%o"
         Set "char[!i16!]=%%p" & Set "char[!i17!]=%%q"
    )
    Set /A "idx+=17"
 )

 rem special handling of ascii code #17
 For /F "tokens=1" %%a In (
   'forfiles /p "%~dp0." /m "%~nx0" /c "cmd /c echo(0xff!"') Do Set "chr255=%%a")
 Set "char[17]=!char[17]!%chr255%"

 Set "c=1"
 Set "counter=17"

 > "asciiTbl.txt" (
     Echo                   BoxTool Border Friendly ASCII Codes ^& Characters

 For /L %%i In (1,1,15) Do (
    Set "numbs="
    For /L %%n In (!c!,1,!counter!) Do (
       Set "str=   %%n %"
       Set "str=!str:~-5!"
       Set "numbs=!numbs!!str!")

    For /L %%t In (!c!,1,!counter!) Do (
       Set "xCode="
       For %%x In (7 8 9 10 13) Do If %%x==%%t Set "xCode=True"
       Set "s=%%t" & Set /A "s-=1"
       Set /A "s=!s!%%17+1"
       Set "c!s!=!char[%%t]!"
    )

    Echo !numbs!
    Set "parms=   !c1!    !c2!    !c3!    !c4!    !c5!"
    Set "parms=!parms!    !c6!    !c7!    !c8!    !c9!    !c10!    !c11!   "
    Set "parms=!parms! !c12!    !c13!    !c14!    !c15!    !c16!    !c17!"
    For /F "tokens=*" %%t in ("!parms!") Do Echo    %%t
    Set /A "counter+=17"
    Set /A "c=!counter!-16")
 )

 type asciiTbl.txt

 endlocal & exit /b


:makeHexString [ret var: string of hex #s for the decimal range 1-255]
 setlocal EnableDelayedExpansion
 Set "string=0 1 2 3 4 5 6 7 8 9 A B C D E F"
 Set "string2=%string: =%"

 Set "i=0"
 For %%a In (%string%) Do (
    For /L %%n In (0,1,15) Do (
       Set "x=!string2:~%%n,1!"
       Set "hex[!i!]=%%a!x!"
       Set /A "i+=1"
 ))

 rem exclude 14 characters that can be a problem manipulating and echoing:
 For %%n In (7 8 9 10 13 26 32 33 38 59 60 62 94 124) Do Set "hex[%%n]=FF"

 rem prepare returned string from the array
 Set "hexStr="
 For /L %%n In (1,1,255) Do Set "hexStr=!hexStr! !hex[%%n]!"

 endlocal & Set "%~1=%hexStr:~1%" & exit /b


edited 3/1/17 - missing end quote Set "i=0"

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Using forfiles with Windows 10 vs Win 7 question

#2 Post by dbenham » 02 Mar 2017 14:21

Your code works just fine for me on Win 10.

I suspect your problem is the font that your console is using. I get empty boxes for the ASCII control characters if I use anything other than a raster font.

You can change the console font by right clicking the console title bar, pick the "properties" option, and then go to the "Font" tab. I like to use Raster 8x12.


Dave Benham

Jer
Posts: 177
Joined: 23 Nov 2014 17:13
Location: California USA

Re: Using forfiles with Windows 10 vs Win 7 question

#3 Post by Jer » 05 Mar 2017 14:03

My one raster font is SimSun-ExtB, which is variable width.

I tried installing several different fonts through regedit, then after re-booting
the new font is not in the console properties/font list.

I posted the issue in a Windows 10 forum but no resolution yet.
Jerry

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Using forfiles with Windows 10 vs Win 7 question

#4 Post by aGerman » 05 Mar 2017 15:48

Jer wrote:My one raster font is SimSun-ExtB

SimSun-ExtB is no raster font. On my Win10 menu SimSun-ExtB is one item farther.

Steffen
rasterfont.PNG
rasterfont.PNG (22.83 KiB) Viewed 6470 times

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Using forfiles with Windows 10 vs Win 7 question

#5 Post by Aacini » 05 Mar 2017 17:27

Jer wrote:My one raster font is SimSun-ExtB, which is variable width.

I tried installing several different fonts through regedit, then after re-booting
the new font is not in the console properties/font list.

I posted the issue in a Windows 10 forum but no resolution yet.
Jerry


"Raster fonts" have not the "TT" (TrueType) symbol and have fixed sizes given as Width x Height.

In order to install new fonts that can be used in the command-line cmd.exe window, they must meet certain criteria. For TrueType fonts, the font must be a fixed-pitch one and cannot be italic. For raster fonts, the face name must be "Terminal" with OEM_CHARSET. Further details at this answer.

Antonio

Jer
Posts: 177
Joined: 23 Nov 2014 17:13
Location: California USA

Re: Using forfiles with Windows 10 vs Win 7 question

#6 Post by Jer » 06 Mar 2017 11:18

Thanks to all. My problem: terminal naivete.

Looking at the console font list I see that all the TueType fonts are
indented in the list while the only line not indented is "Raster Fonts". I took this
to be a label for the one font that followed :oops:

This appeared to me to be a setback for my 3 projects, BoxTool, a batch-code-only
script for boxing your text (or blanks), ColorShow applications: CBoard release 2 (checkerboards)
and FrameTool release 2 (framed text and grid of frames). I thought I might have to abandon
ascii characters, codes 1-31, to accommodate Windows 10 O/S.

Now there is no need to look for another font.
Solved.
Jerry

Post Reply