Xcopy help reading key

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
batnoob
Posts: 56
Joined: 19 Apr 2017 12:23

Xcopy help reading key

#1 Post by batnoob » 03 Apr 2018 09:02

I've been modifying and expanding my Graphing Calculator and decided to see if I could add vt100 escapes to maybe make it faster, it had been working fine, until i added a method to find the windows version, so the file could pick between <TAB><BS><BS> method or the vt100 escapes, but when I put that code into the file and ran it from command prompt, I got a weird Error from the menu:

Code: Select all

The system cannot find the batch label specified - Thing_d
the menu uses xcopy to get the key pressed and goes to the label

Code: Select all

:Thing_%input%
xcopy is supposed to wait for input before it copies anything, then set the variable as the key pressed, but it would seem that it doesn't wait, copies no files, creates the message "0 files copied", then sets the variable to "d", the last letter in that string.
I cannot seem to fix this, it only seems to happen when I open the batch file from command prompt.
Not sure if it is necessary, but here is the entire code:

Code: Select all

:setup
@echo off
setlocal enableDelayedExpansion
REM capture escape char for VT100
for /F %%a in ('echo prompt $E^| cmd') do set "ESC=%%a"
REM find out WinVer to see if vt100 escapes work
for /f "tokens=4 delims= " %%a in ('ver') do set j=%%a
set i=%j:~0,2%
if "%i%" == "10" set "isWinTen=true"
title Graphing Calculator by BatNoob
color 9f
mode 120,120
set "TAB=	"
set ^"LF=^

^" Above empty line is required - do not remove
set ^"$n=^^^%LF%%LF%^%LF%%LF%^^"


pause
:menu
cls
echo ÛÛÛÛÛ  ÛÛÛÛÛ  ÛÛÛÛÛ  ÛÛÛÛÛ  Û   Û  ÛÛÛÛÛ  Û   Û  ÛÛÛÛÛ
echo Û      Û   Û  Û   Û  Û   Û  Û   Û    Û    ÛÛ  Û  Û
echo Û ÛÛÛ  ÛÛÛÛÛ  ÛÛÛÛÛ  ÛÛÛÛÛ  ÛÛÛÛÛ    Û    Û Û Û  Û ÛÛÛ
echo Û   Û  Û  Û   Û   Û  Û      Û   Û    Û    Û  ÛÛ  Û   Û
echo ÛÛÛÛÛ  Û   Û  Û   Û  Û      Û   Û  ÛÛÛÛÛ  Û   Û  ÛÛÛÛÛ
echo/
echo ÛÛÛÛÛ  ÛÛÛÛÛ  ÛÛ     ÛÛÛÛÛ  Û   Û  ÛÛ     ÛÛÛÛÛ  ÛÛÛÛÛ  ÛÛÛÛÛ  ÛÛÛÛÛ  ÛÛ
echo Û      Û   Û  Û      Û      Û   Û  Û      Û   Û    Û    Û   Û  Û   Û  ÛÛ
echo Û      ÛÛÛÛÛ  Û      Û      Û   Û  Û      ÛÛÛÛÛ    Û    Û   Û  ÛÛÛÛÛ  ÛÛ
echo Û      Û   Û  Û      Û      Û   Û  Û      Û   Û    Û    Û   Û  Û  Û    
echo ÛÛÛÛÛ  Û   Û  ÛÛÛÛÛ  ÛÛÛÛÛ   ÛÛÛ   ÛÛÛÛÛ  Û   Û    Û    ÛÛÛÛÛ  Û   Û  ÛÛ

echo/
echo/
set "op1=1. Graphing Calc "
set "op2=2. Options"
if exist "File.txt" (
	for /f "tokens=1-2 delims=," %%t in (File.txt) do (
		set "max=%%t"
		color %%u
	)
)
set "op3=3. Exit "
set "op4=4. Restart "

echo ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ
echo Û %op1%%TAB%Û
echo Û %op2%%TAB%%tab%Û
echo Û %op3%%TAB%%tab%Û
echo Û %op4%%TAB%%TAB%Û
echo ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ

set "label="
for /f "eol=1 delims=" %%i in ('xcopy /lwq "%~f0" :\') do set "label=%%i"
set "label=Thing_!label:~-1!"
goto :%label%
exit /b


:Thing_4
start cmd /c %0
exit



goto :menu

:Thing_2
cls
echo ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ
echo Û 1. Size          Û
echo Û 2. Color         Û
echo Û 3. Clear         Û
echo ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ

set "key="
for /F "delims=" %%k in ('xcopy /W "%~F0" "%~F0" 2^>NUL') do if not defined key set "key=%%k"
for /F %%k in ("!key:~-1!") do (set nkey=%%k)
If !nkey! == 1 (
	set /p "max=Size (1-58): "
) Else if !nkey! == 2 (
	set /p "Col=Color: "
) else if "!nkey!" == "3" (
	ERASE File.txt
	goto :menu
) else (
	set max=50
	goto :Thing_2
)
if defined Col (color %Col%)
<nul set /p "=!max!" >File.txt
<nul set /p "=," >> File.txt
<nul set /p "=!Col!" >>File.txt
goto :menu

:Thing_3
exit

:Thing_1
cls
::*****************************************************************MAIN***********************************************************************************
::::::::::::::::::::::::::::::::::::::::::
::setting <tab>  and <bs>
for /F %%a in ('echo prompt $H ^| cmd') do set "BS=%%a"
set "TAB=	"
::
::::::::::::::::::::::::::::::::::::::::::

::::::::::::::::::::::::::::::::::::::::::
::set the math functions from https://www.dostips.com/forum/viewtopic.phpÛf=3&t=5819
set "Abs[x]=(((x)>>31|1)*(x))"	& REM Absolute Value
set "Sign[x]=(x)>>31 | -(x)>>31 & 1"	& REM Returns the sign of the number
set "AVG[xy]=(X&Y)+(X^Y)/2"	& REM Average
:: they don't work to type in.
::::::::::::::::::::::::::::::::::::::::::

set "start=0" 		::part of my improvised Do While Loop
If not defined max (set max=55)
set /a min=max*(-1)
set /a ymax=(!max!/2)-5
set /a ymin=(ymax * -1)
set /a nmax=2*!max!+2
if not defined char (set "char=2")
set "eq="
set/p "eq=Type equation, Put spaces between all characters: "
:::::::::::::::::::::::::::::::::::::::::::::Checking Validity::::::::::::::::::
set "check=%eq: =.%"
set fact=good
call :strlen len eq
::make sure that equation isn't too long for the "checker"
if %len% GTR 48 (set fact=bad)
:: make sure there are spaces
if !eq! == !check! (set fact=bad)
set "bad=A B C D E F G H I J K L M N O P Q R S T U V W Z"
:: Check if any of the "bad" chars are in the equation.
set "stop=False"
for %%a in (%eq%) do (
	for %%A in (%bad%) do (
		if /i "%%a" == "%%A" (set "stop=true")
	)
)
:: go back to beginning if the equation is bad
if "!fact!"=="bad" (goto :Thing_1)
if "%stop%" == "true" (goto :Thing_1)
::make sure %eq% isn't empty and got though the "checker"
If "%eq%" == " " goto :Thing_1

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::Begin actual work
set "neq=!eq:x=((-1)*x)!"	:: Graphing on both sides of the y axis
set "X=0"
set "Y=0"
set /a "nX=X* (-1)"
set /a "nY=Y* (-1)"
cls
::echo/
:call
Call :start & rem << to stop the random exiting that occurred whenever !X! was greater than !max!
pause
Call :ClearVars &REM reset the graph
goto :menu

:start 
REM Goto loop Acting as a DO WHILE loop, is there something more efficientÛ
set /a "start=!start!+1"
if !start! GEQ 2 (set /a "X+=1")
set /a "Y=%eq%" 	 & REM thanks to @aGerman and @Aacini for helping me with this.
set /a "nX=x*(-1)"
set /a "nY=%neq%"
if "!x!" NEQ "0" (if "!y!" neq "0" (if "!nx!" NEQ "0" (if "!ny!" neq "0" (set "char=Û")))) else (set "char=Û")
set !x!-!y!=!char!
set !nX!-!nY!=!char!
For /l %%a in (0 1 !nmax!) do (<nul set/p "=Û")
echo/
rem draw the graph.
for /l %%y in (!ymax! -1 !ymin!) do (
	<nul set/p "=Û"
	for /l %%x in (!min! 1 !max!) do (
		If not defined %%x-%%y (
			If "%%x" Neq "0" (
				If "%%y" NEQ "0" (
					set "%%x-%%y=Û"
				) Else (
					set "%%x-%%y=Û"
				)
			) Else (
				set "%%x-%%y=Û"
			)
		) 	& rem if statement marks the axes
		<nul set/p "=!%%x-%%y!"
	)
	echo Û%%y
)
For /l %%a in (0 1 !nmax!) do (<nul set/p "=Û")
echo/
set /a "nBSs=(!ymax!+5)*28"
set "BSs="
for /l %%# in (1 1 !nBSs!) do (set "BSs=!BSs!!BS!") & Rem <tab><bs><bs> method described by Aacini is faster than Timeout method,
::														also explained by Aacini

if %isWinTen% NEQ true (
	echo %TAB%%BSs%@ 2>nul & Rem Moving cursor to screen home.
) else (
	echo %ESC%[H & REM use vt100 escape sequences if isWinTen = true
)
If !nx! LSS !max! (
	If !ny! LSS !ymax! (
		If !nx! GTR !min! (
			If !ny! GTR !ymin! (
				REM 					Second half
				If !X! LSS !max! (
					If !Y! LSS !ymax! (
						If !X! GTR !min! (
							If !Y! GTR !ymin! (
								goto :start &REM                   Troublesome if statement, first half works, but not the second
							)
						)
					)
				)
			)
		)
	)
) Else (exit /b)
endlocal

::--------------------------------------------------Functions------------------------------------------------------------------------
goto :eof

:ColorText color text
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
  set "DEL=%%a"
)
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1
goto :eof

:ClearVars 

for /l %%y in (!ymax! -1 !ymin!) do (
	for /l %%x in (!min! 1 !max!) do (
	set "%%x-%%y="
	)
)

exit /b

:strlen <resultVar> <stringVar>
(   
    setlocal EnableDelayedExpansion
    set "s=!%~2!#"
    set "len=0"
    for %%P in (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) do (
        if "!s:~%%P,1!" NEQ "" ( 
            set /a "len+=%%P"
            set "s=!s:~%%P!"
        )
    )
)
( 
    endlocal
    set "%~1=%len%"
    exit /b
)

Last edited by batnoob on 03 Apr 2018 13:31, edited 1 time in total.

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

Re: Xcopy help reading key

#2 Post by aGerman » 03 Apr 2018 09:42

Try

Code: Select all

set "label="
for /f "eol=1 delims=" %%i in ('xcopy /lwq "%~f0" :\') do set "label=%%i"
set "label=Thing_%label:~-1%"
Reference:
viewtopic.php?f=3&t=5519&p=33741#p33741

Steffen

batnoob
Posts: 56
Joined: 19 Apr 2017 12:23

Re: Xcopy help reading key

#3 Post by batnoob » 03 Apr 2018 10:58

Thank you, that seemed to have worked ( but I'm reminded of the song that goes: 2 little bugs in the code 2 little bugs, you fix them out, test them again-- 40 little bugs in the code.)

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

Re: Xcopy help reading key

#4 Post by aGerman » 03 Apr 2018 11:15

Haha. No wonder if you write the whole script even if you already had a bug in the first few lines.

FWIW The л in your code does not exist in one of my default codepages. Long thread about non-ASCII:
viewtopic.php?f=3&t=7701
For now you should keep it simple and use ASCII characters such as # or * or @.

Steffen

batnoob
Posts: 56
Joined: 19 Apr 2017 12:23

Re: Xcopy help reading key

#5 Post by batnoob » 03 Apr 2018 12:32

i know, Notepad++ wont let me Show my script in ANSI for some reason, it shows in ISO 8859-5. it's weird, but when i open in normal note pad, it shows in ANSI correctly

batnoob
Posts: 56
Joined: 19 Apr 2017 12:23

Re: Xcopy help reading key

#6 Post by batnoob » 03 Apr 2018 12:33

but it does translate to the full █ block in the console window

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

Re: Xcopy help reading key

#7 Post by aGerman » 03 Apr 2018 13:30

Saved in the editor with your local editor settings (ISO 8859-5 as you mentioned), displayed in the console window with your local OEM codepage (most likely CP 866 in your case). Only people with your settings see the same like you. I can't even save a script that contains a cyrillic л because it doesn't belong to my default codepages that are, Windows-1252 for the editor and CP 850 for the console window. You should really read the linked thread :wink:

Steffen

batnoob
Posts: 56
Joined: 19 Apr 2017 12:23

Re: Xcopy help reading key

#8 Post by batnoob » 03 Apr 2018 13:34

edited the code posted here (about to edit the code in my other graphing calculator post) to show the "Û" char instead of the "л" char

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

Re: Xcopy help reading key

#9 Post by aGerman » 03 Apr 2018 13:50

Now it works for the people from the western hemisphere but not for you anymore. Not even for the central European people whose codepages default to 1250 and 852. Not for Greek people, not for Chinese or Arabic people etc.
Nevermind. Don't worry about that. If you want to solve that problem you should still read the linked thread.

batnoob
Posts: 56
Joined: 19 Apr 2017 12:23

Re: Xcopy help reading key

#10 Post by batnoob » 03 Apr 2018 14:18

1. I read the topic, thanks for pointing me towards it.
2. I am in the western hemisphere, but the version of notepad++ that i have wont recognize the Û character in ANSI encoding, and changes the encoding to the ISO-whatever encoding, which has the л Character, and i'm not sure how to fix this (maybe re-install)

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

Re: Xcopy help reading key

#11 Post by aGerman » 03 Apr 2018 14:34

In NP++ menu Settings -> Preferences -> New Document
In the Encoding frame select either ANSI (if the default ANSI codepage on your machine is Windows-1252) or select the last item and choose Windows-1252 manually from the dropdown.

Steffen

batnoob
Posts: 56
Joined: 19 Apr 2017 12:23

Re: Xcopy help reading key

#12 Post by batnoob » 03 Apr 2018 14:45

Thank you, you have been a big help.

Post Reply