Solved [Help?] batch-parameter substitution substitution

ThumpieBunnyEve

New member
Local time
4:16 PM
Messages
25
I have a little problem of a batch,
Justa sootch, for some hooch, will you help a Paisano?
parameter's im slighting, variables im fighting! me!

HelpMeYo, HelpMeYo,
HelpMeYo, HelpMeYo,
HelpMe~ YouGotaHelpaBro!


So I've got some problems getting Batch, to allow me to parameter substitution on my own vars.
It normally works with command line parameters. which are given the var names 0 1 2 3 4 and so on at the start of a batch environment.
so something like "C:/Freddy Mercury/Bohemian/Rhapsody.exe" "C:/reload/rob zombie.ogg" "N:/ever/gona/give/u.up" "I:/love/ewe/u/love.me"
would result in the environment of the running batch having the vars 0 1 2 3 being the 4 above quoted elements.
Then you can use parameter expansion/substitution on them, to get just the path or file name or extension.
so for example with the above parameters passed...

echo %%~n3
echo %%~x3
echo %%~x2
echo %%~n2

would result in

love
me
up
rob zombie

eew... but anyway, i want to insert my own vars through this process inside the running batch file.
somehow that sounds more seedy now then its meant to be... but moving on..

here is my code.. which does not work.

Code:
Code:
[COLOR=#F1F2F3][FONT=verdana]
[/FONT][/COLOR][COLOR=#949494][FONT=verdana][COLOR=#FACD22 @[URL="https://www.sevenforums.com/members/echo.html"]echo[/URL][/FONT][/COLOR][FONT=verdana][COLOR=#678CB1]Off[/COLOR][COLOR=#F1F2F3]
echo [/COLOR][COLOR=#F1F2F3]%~[/COLOR][COLOR=#F1F2F3]nx0 running[/COLOR][COLOR=#F1F2F3].[/COLOR][COLOR=#F1F2F3]
[/COLOR][COLOR=#93C763]set[/COLOR][COLOR=#F1F2F3] uhray[/COLOR][COLOR=#F1F2F3][[/COLOR][COLOR=#FACD22]0[/COLOR][COLOR=#F1F2F3]]=[/COLOR][COLOR=#F1F2F3]A[/COLOR][COLOR=#F1F2F3]:[/COLOR][COLOR=#F1F2F3]\BatchPlayground\NoFile[/COLOR][COLOR=#F1F2F3].[/COLOR][COLOR=#F1F2F3]exe
[/COLOR][COLOR=#93C763]set[/COLOR][COLOR=#F1F2F3] uhray[/COLOR][COLOR=#F1F2F3][[/COLOR][COLOR=#FACD22]1[/COLOR][COLOR=#F1F2F3]]=[/COLOR][COLOR=#F1F2F3]B[/COLOR][COLOR=#F1F2F3]:[/COLOR][COLOR=#F1F2F3]\CmdBrainStorming\NonExistantFile[/COLOR][COLOR=#F1F2F3].[/COLOR][COLOR=#F1F2F3]doh
[/COLOR][COLOR=#93C763]set[/COLOR][COLOR=#F1F2F3] uhray[/COLOR][COLOR=#F1F2F3][[/COLOR][COLOR=#FACD22]2[/COLOR][COLOR=#F1F2F3]]=[/COLOR][COLOR=#F1F2F3]C[/COLOR][COLOR=#F1F2F3]:[/COLOR][COLOR=#F1F2F3]\SomeOtherPlace\FictionalFile[/COLOR][COLOR=#F1F2F3].[/COLOR][COLOR=#F1F2F3]lalala
SETLOCAL ENABLEDELAYEDEXPANSION
[/COLOR][COLOR=#93C763]set[/COLOR][COLOR=#F1F2F3] z[/COLOR][COLOR=#F1F2F3]=[/COLOR][COLOR=#FACD22]0[/COLOR][COLOR=#F1F2F3]
[/COLOR][COLOR=#F1F2F3]:[/COLOR][COLOR=#678CB1]SymLoop[/COLOR][COLOR=#F1F2F3]
[/COLOR][COLOR=#93C763]if[/COLOR][COLOR=#93C763]defined[/COLOR][COLOR=#F1F2F3] uhray[/COLOR][COLOR=#F1F2F3][%[/COLOR][COLOR=#F1F2F3]z[/COLOR][COLOR=#F1F2F3]%][/COLOR][COLOR=#F1F2F3]([/COLOR][COLOR=#F1F2F3]
    echo uhray[/COLOR][COLOR=#F1F2F3][%[/COLOR][COLOR=#F1F2F3]z[/COLOR][COLOR=#F1F2F3]%]=[/COLOR][COLOR=#F1F2F3]![/COLOR][COLOR=#F1F2F3]uhray[/COLOR][COLOR=#F1F2F3][%[/COLOR][COLOR=#F1F2F3]z[/COLOR][COLOR=#F1F2F3]%]![/COLOR][COLOR=#F1F2F3]
    echo [/COLOR][COLOR=#F1F2F3]%%~[/COLOR][COLOR=#F1F2F3]x[/COLOR][COLOR=#F1F2F3]![/COLOR][COLOR=#F1F2F3]uhray[/COLOR][COLOR=#F1F2F3][%[/COLOR][COLOR=#F1F2F3]z[/COLOR][COLOR=#F1F2F3]%]![/COLOR][COLOR=#F1F2F3]
    [/COLOR][COLOR=#93C763]set[/COLOR][COLOR=#F1F2F3]/[/COLOR][COLOR=#F1F2F3]a [/COLOR][COLOR=#EC7600]"z+=1"[/COLOR][COLOR=#F1F2F3]
    GOTO [/COLOR][COLOR=#F1F2F3]:[/COLOR][COLOR=#678CB1]SymLoop[/COLOR][COLOR=#F1F2F3]
[/COLOR][COLOR=#F1F2F3])[/COLOR][COLOR=#F1F2F3]
[/COLOR][COLOR=#93C763]set[/COLOR][COLOR=#F1F2F3] z[/COLOR][COLOR=#F1F2F3]=[/COLOR][COLOR=#F1F2F3]
ENDLOCAL

REM [/COLOR][COLOR=#F1F2F3].[/COLOR][COLOR=#F1F2F3]
REM [/COLOR][COLOR=#F1F2F3].[/COLOR][COLOR=#F1F2F3]
REM [/COLOR][COLOR=#F1F2F3].[/COLOR][COLOR=#F1F2F3]
REM  everything below here causes a substitution invalid error [/COLOR][COLOR=#93C763]in[/COLOR][COLOR=#F1F2F3] the script even [/COLOR][COLOR=#93C763]when[/COLOR][COLOR=#F1F2F3] its [/COLOR][COLOR=#93C763]in[/COLOR][COLOR=#F1F2F3] a REMARK[/COLOR][COLOR=#F1F2F3].[/COLOR][COLOR=#F1F2F3]@,@?[/COLOR][COLOR=#F1F2F3]
REM    echo [/COLOR][COLOR=#F1F2F3]%%~[/COLOR][COLOR=#F1F2F3]x[/COLOR][COLOR=#F1F2F3]![/COLOR][COLOR=#F1F2F3]uhray[/COLOR][COLOR=#F1F2F3][%[/COLOR][COLOR=#F1F2F3]z[/COLOR][COLOR=#F1F2F3]%]![/COLOR][COLOR=#F1F2F3]
REM    [/COLOR][COLOR=#93C763]set[/COLOR][COLOR=#F1F2F3] q[/COLOR][COLOR=#F1F2F3]=%[/COLOR][COLOR=#F1F2F3]uhray[/COLOR][COLOR=#F1F2F3][![/COLOR][COLOR=#F1F2F3]z[/COLOR][COLOR=#F1F2F3]!]%...[/COLOR][COLOR=#F1F2F3]
REM    call echo [/COLOR][COLOR=#F1F2F3]%%~[/COLOR][COLOR=#F1F2F3]xq
REM    echo [/COLOR][COLOR=#F1F2F3]%%~[/COLOR][COLOR=#F1F2F3]x[/COLOR][COLOR=#F1F2F3]![/COLOR][COLOR=#F1F2F3]uhray[/COLOR][COLOR=#F1F2F3][%[/COLOR][COLOR=#F1F2F3]z[/COLOR][COLOR=#F1F2F3]%]![/COLOR][COLOR=#F1F2F3]
REM    call echo [/COLOR][COLOR=#F1F2F3]%~[/COLOR][COLOR=#F1F2F3]x[/COLOR][COLOR=#F1F2F3]![/COLOR][COLOR=#F1F2F3]uhray[/COLOR][COLOR=#F1F2F3][%[/COLOR][COLOR=#F1F2F3]z[/COLOR][COLOR=#F1F2F3]%]![/COLOR][COLOR=#F1F2F3]
REM    call echo [/COLOR][COLOR=#F1F2F3]%%~[/COLOR][COLOR=#F1F2F3]x[/COLOR][COLOR=#F1F2F3]![/COLOR][COLOR=#F1F2F3]uhray[/COLOR][COLOR=#F1F2F3][%[/COLOR][COLOR=#F1F2F3]z[/COLOR][COLOR=#F1F2F3]%]![/COLOR][COLOR=#F1F2F3]
REM    [/COLOR][COLOR=#93C763]set[/COLOR][COLOR=#F1F2F3] Q[/COLOR][COLOR=#F1F2F3]=![/COLOR][COLOR=#F1F2F3]uhray[/COLOR][COLOR=#F1F2F3][%[/COLOR][COLOR=#F1F2F3]z[/COLOR][COLOR=#F1F2F3]%]![/COLOR][COLOR=#F1F2F3]
REM    echo [/COLOR][COLOR=#F1F2F3]%%~[/COLOR][COLOR=#F1F2F3]x[/COLOR][COLOR=#F1F2F3]%[/COLOR][COLOR=#F1F2F3]Q[/COLOR][COLOR=#F1F2F3]%
[/COLOR][/FONT][/COLOR]


Output:
Code:
[COLOR=#949494][FONT=verdana]
[COLOR=#F1F2F3]C[/COLOR][COLOR=#F1F2F3]:[/COLOR][COLOR=#F1F2F3]\BatchPlayground[/COLOR][COLOR=#F1F2F3]>[/COLOR][COLOR=#F1F2F3]C[/COLOR][COLOR=#F1F2F3]:[/COLOR][COLOR=#F1F2F3]\BatchPlayground\Substitutetutelage2[/COLOR][COLOR=#F1F2F3].[/COLOR][COLOR=#F1F2F3]bat
[/COLOR][COLOR=#678CB1]Substitutetutelage2[/COLOR][COLOR=#F1F2F3].[/COLOR][COLOR=#F1F2F3]bat running[/COLOR][COLOR=#F1F2F3].[/COLOR][COLOR=#F1F2F3]
uhray[/COLOR][COLOR=#F1F2F3][[/COLOR][COLOR=#FACD22]0[/COLOR][COLOR=#F1F2F3]]=[/COLOR][COLOR=#F1F2F3] A[/COLOR][COLOR=#F1F2F3]:[/COLOR][COLOR=#F1F2F3]\BatchPlayground\NoFile[/COLOR][COLOR=#F1F2F3].[/COLOR][COLOR=#F1F2F3]exe
[/COLOR][COLOR=#F1F2F3]%~[/COLOR][COLOR=#F1F2F3]xA[/COLOR][COLOR=#F1F2F3]:[/COLOR][COLOR=#F1F2F3]\BatchPlayground\NoFile[/COLOR][COLOR=#F1F2F3].[/COLOR][COLOR=#F1F2F3]exe
uhray[/COLOR][COLOR=#F1F2F3][[/COLOR][COLOR=#FACD22]1[/COLOR][COLOR=#F1F2F3]]=[/COLOR][COLOR=#F1F2F3] B[/COLOR][COLOR=#F1F2F3]:[/COLOR][COLOR=#F1F2F3]\CmdBrainStorming\NonExistantFile[/COLOR][COLOR=#F1F2F3].[/COLOR][COLOR=#F1F2F3]doh
[/COLOR][COLOR=#F1F2F3]%~[/COLOR][COLOR=#F1F2F3]xB[/COLOR][COLOR=#F1F2F3]:[/COLOR][COLOR=#F1F2F3]\CmdBrainStorming\NonExistantFile[/COLOR][COLOR=#F1F2F3].[/COLOR][COLOR=#F1F2F3]doh
uhray[/COLOR][COLOR=#F1F2F3][[/COLOR][COLOR=#FACD22]2[/COLOR][COLOR=#F1F2F3]]=[/COLOR][COLOR=#F1F2F3] C[/COLOR][COLOR=#F1F2F3]:[/COLOR][COLOR=#F1F2F3]\SomeOtherPlace\FictionalFile[/COLOR][COLOR=#F1F2F3].[/COLOR][COLOR=#F1F2F3]lalala
[/COLOR][COLOR=#F1F2F3]%~[/COLOR][COLOR=#F1F2F3]xC[/COLOR][COLOR=#F1F2F3]:[/COLOR][COLOR=#F1F2F3]\SomeOtherPlace\FictionalFile[/COLOR][COLOR=#F1F2F3].[/COLOR][COLOR=#F1F2F3]lalala
[/COLOR][COLOR=#678CB1]The[/COLOR][COLOR=#F1F2F3] following usage [/COLOR][COLOR=#93C763]of[/COLOR][COLOR=#F1F2F3] the path [/COLOR][COLOR=#93C763]operator[/COLOR][COLOR=#93C763]in[/COLOR][COLOR=#F1F2F3] batch[/COLOR][COLOR=#F1F2F3]-[/COLOR][COLOR=#F1F2F3]parameter
substitution [/COLOR][COLOR=#93C763]is[/COLOR][COLOR=#F1F2F3] invalid[/COLOR][COLOR=#F1F2F3]:[/COLOR][COLOR=#F1F2F3]%~[/COLOR][COLOR=#F1F2F3]x[/COLOR][COLOR=#F1F2F3]![/COLOR][COLOR=#F1F2F3]uhray[/COLOR][COLOR=#F1F2F3][%[/COLOR][COLOR=#F1F2F3]z[/COLOR][COLOR=#F1F2F3]%]![/COLOR][COLOR=#F1F2F3]


[/COLOR][COLOR=#678CB1]For[/COLOR][COLOR=#F1F2F3] valid formats type CALL [/COLOR][COLOR=#F1F2F3]/?[/COLOR][COLOR=#93C763]or[/COLOR][COLOR=#F1F2F3] FOR [/COLOR][COLOR=#F1F2F3]/?[/COLOR][COLOR=#F1F2F3]
[/COLOR][COLOR=#678CB1]The[/COLOR][COLOR=#F1F2F3] syntax [/COLOR][COLOR=#93C763]of[/COLOR][COLOR=#F1F2F3] the command [/COLOR][COLOR=#93C763]is[/COLOR][COLOR=#F1F2F3] incorrect[/COLOR][COLOR=#F1F2F3].[/COLOR][COLOR=#F1F2F3]

C[/COLOR][COLOR=#F1F2F3]:[/COLOR][COLOR=#F1F2F3]\BatchPlayground[/COLOR][COLOR=#F1F2F3]>[/COLOR][/FONT][/COLOR]

Expected Output:
Code:
[COLOR=#949494][FONT=verdana]
[COLOR=#F1F2F3]C[/COLOR][COLOR=#F1F2F3]:[/COLOR][COLOR=#F1F2F3]\BatchPlayground[/COLOR][COLOR=#F1F2F3]>[/COLOR][COLOR=#F1F2F3]C[/COLOR][COLOR=#F1F2F3]:[/COLOR][COLOR=#F1F2F3]\BatchPlayground\Substitutetutelage2[/COLOR][COLOR=#F1F2F3].[/COLOR][COLOR=#F1F2F3]bat
[/COLOR][COLOR=#678CB1]Substitutetutelage2[/COLOR][COLOR=#F1F2F3].[/COLOR][COLOR=#F1F2F3]bat running[/COLOR][COLOR=#F1F2F3].[/COLOR][COLOR=#F1F2F3]
uhray[/COLOR][COLOR=#F1F2F3][[/COLOR][COLOR=#FACD22]0[/COLOR][COLOR=#F1F2F3]]=[/COLOR][COLOR=#F1F2F3] A[/COLOR][COLOR=#F1F2F3]:[/COLOR][COLOR=#F1F2F3]\BatchPlayground\NoFile[/COLOR][COLOR=#F1F2F3].[/COLOR][COLOR=#F1F2F3]exe
exe
uhray[/COLOR][COLOR=#F1F2F3][[/COLOR][COLOR=#FACD22]1[/COLOR][COLOR=#F1F2F3]]=[/COLOR][COLOR=#F1F2F3] B[/COLOR][COLOR=#F1F2F3]:[/COLOR][COLOR=#F1F2F3]\CmdBrainStorming\NonExistantFile[/COLOR][COLOR=#F1F2F3].[/COLOR][COLOR=#F1F2F3]doh
doh
uhray[/COLOR][COLOR=#F1F2F3][[/COLOR][COLOR=#FACD22]2[/COLOR][COLOR=#F1F2F3]]=[/COLOR][COLOR=#F1F2F3] C[/COLOR][COLOR=#F1F2F3]:[/COLOR][COLOR=#F1F2F3]\SomeOtherPlace\FictionalFile[/COLOR][COLOR=#F1F2F3].[/COLOR][COLOR=#F1F2F3]lalala
lalala

C[/COLOR][COLOR=#F1F2F3]:[/COLOR][COLOR=#F1F2F3]\BatchPlayground[/COLOR][COLOR=#F1F2F3]>[/COLOR][/FONT][/COLOR]

I've posted this problem over on "stack overflow" too. but immediately got downvoted into oblivion for not knowing batch code.
i mean.. that is kinda the point, if your asking for help, your admitting you need help learning it better. Maybe its just troll'y over there.

TLDR: trying to get var.expansion/substitution operational with array Vars, and not just the typical %1 %2 %3 it seems to be restricted to.
The definitions for things like %~n and %~nx and %%~p are inside the FOR /? help sheet oddly enough. Though they can clearly be used without a CALL or FOR itself.

If anyone has the smart beanie to spin their propeller on this, please weigh in and flex that grey muscle for me.
I've been falling up stairs on this one all the dog-gone-day.




....::::Its been a few days now looking for answers.::::....




Some expressed it was too complicated to understand in its above state, so im re-stating it with a lot less code involved.
lines 1,
and 2, work,
line 3, returns an error relating to the usage of var. extension substitution.


The same problem exists whether i use an array or not for the var.
Code:
Code:
[COLOR=#F1F2F3][FONT=verdana]
[/FONT][/COLOR][COLOR=#949494][FONT=verdana][COLOR=#F1F2F3]echo [/COLOR][COLOR=#F1F2F3]%~[/COLOR][COLOR=#F1F2F3]nx0 running[/COLOR][COLOR=#F1F2F3].[/COLOR][COLOR=#F1F2F3]
[/COLOR][COLOR=#93C763]set[/COLOR][COLOR=#F1F2F3] I[/COLOR][COLOR=#F1F2F3]=[/COLOR][COLOR=#F1F2F3]B[/COLOR][COLOR=#F1F2F3]:[/COLOR][COLOR=#F1F2F3]\CmdBrainStorming\NonExistantFile[/COLOR][COLOR=#F1F2F3].[/COLOR][COLOR=#F1F2F3]doh
echo [/COLOR][COLOR=#F1F2F3]%~[/COLOR][COLOR=#F1F2F3]xI[/COLOR][/FONT][/COLOR]


Output:

Code:
[COLOR=#949494][FONT=verdana]
[COLOR=#F1F2F3]C[/COLOR][COLOR=#F1F2F3]:[/COLOR][COLOR=#F1F2F3]\BatchPlayground[/COLOR][COLOR=#F1F2F3]>[/COLOR][COLOR=#F1F2F3]C[/COLOR][COLOR=#F1F2F3]:[/COLOR][COLOR=#F1F2F3]\BatchPlayground\Substitutetutelage3[/COLOR][COLOR=#F1F2F3].[/COLOR][COLOR=#F1F2F3]bat

C[/COLOR][COLOR=#F1F2F3]:[/COLOR][COLOR=#F1F2F3]\BatchPlayground[/COLOR][COLOR=#F1F2F3]>[/COLOR][COLOR=#F1F2F3]echo [/COLOR][COLOR=#678CB1]Substitutetutelage3[/COLOR][COLOR=#F1F2F3].[/COLOR][COLOR=#F1F2F3]bat running[/COLOR][COLOR=#F1F2F3].[/COLOR][COLOR=#F1F2F3]
[/COLOR][COLOR=#678CB1]Substitutetutelage3[/COLOR][COLOR=#F1F2F3].[/COLOR][COLOR=#F1F2F3]bat running[/COLOR][COLOR=#F1F2F3].[/COLOR][COLOR=#F1F2F3]

C[/COLOR][COLOR=#F1F2F3]:[/COLOR][COLOR=#F1F2F3]\BatchPlayground[/COLOR][COLOR=#F1F2F3]>[/COLOR][COLOR=#93C763]set[/COLOR][COLOR=#F1F2F3] I[/COLOR][COLOR=#F1F2F3]=[/COLOR][COLOR=#F1F2F3]B[/COLOR][COLOR=#F1F2F3]:[/COLOR][COLOR=#F1F2F3]\CmdBrainStorming\NonExistantFile[/COLOR][COLOR=#F1F2F3].[/COLOR][COLOR=#F1F2F3]doh
[/COLOR][COLOR=#678CB1]The[/COLOR][COLOR=#F1F2F3] following usage [/COLOR][COLOR=#93C763]of[/COLOR][COLOR=#F1F2F3] the path [/COLOR][COLOR=#93C763]operator[/COLOR][COLOR=#93C763]in[/COLOR][COLOR=#F1F2F3] batch[/COLOR][COLOR=#F1F2F3]-[/COLOR][COLOR=#F1F2F3]parameter
substitution [/COLOR][COLOR=#93C763]is[/COLOR][COLOR=#F1F2F3] invalid[/COLOR][COLOR=#F1F2F3]:[/COLOR][COLOR=#F1F2F3]%~[/COLOR][COLOR=#F1F2F3]xI


[/COLOR][COLOR=#678CB1]For[/COLOR][COLOR=#F1F2F3] valid formats type CALL [/COLOR][COLOR=#F1F2F3]/?[/COLOR][COLOR=#93C763]or[/COLOR][COLOR=#F1F2F3] FOR [/COLOR][COLOR=#F1F2F3]/?[/COLOR][COLOR=#F1F2F3]

C[/COLOR][COLOR=#F1F2F3]:[/COLOR][COLOR=#F1F2F3]\BatchPlayground[/COLOR][COLOR=#F1F2F3]>[/COLOR][COLOR=#F1F2F3]echo [/COLOR][COLOR=#F1F2F3]%~[/COLOR][COLOR=#F1F2F3]xI

C[/COLOR][COLOR=#F1F2F3]:[/COLOR][COLOR=#F1F2F3]\BatchPlayground[/COLOR][COLOR=#F1F2F3]>[/COLOR][/FONT][/COLOR]


Expected Output:
Code:
[COLOR=#949494][FONT=verdana]
[COLOR=#F1F2F3]C[/COLOR][COLOR=#F1F2F3]:[/COLOR][COLOR=#F1F2F3]\BatchPlayground[/COLOR][COLOR=#F1F2F3]>[/COLOR][COLOR=#F1F2F3]C[/COLOR][COLOR=#F1F2F3]:[/COLOR][COLOR=#F1F2F3]\BatchPlayground\Substitutetutelage3[/COLOR][COLOR=#F1F2F3].[/COLOR][COLOR=#F1F2F3]bat

C[/COLOR][COLOR=#F1F2F3]:[/COLOR][COLOR=#F1F2F3]\BatchPlayground[/COLOR][COLOR=#F1F2F3]>[/COLOR][COLOR=#F1F2F3]echo [/COLOR][COLOR=#678CB1]Substitutetutelage3[/COLOR][COLOR=#F1F2F3].[/COLOR][COLOR=#F1F2F3]bat running[/COLOR][COLOR=#F1F2F3].[/COLOR][COLOR=#F1F2F3]
[/COLOR][COLOR=#678CB1]Substitutetutelage3[/COLOR][COLOR=#F1F2F3].[/COLOR][COLOR=#F1F2F3]bat running[/COLOR][COLOR=#F1F2F3].[/COLOR][COLOR=#F1F2F3]

C[/COLOR][COLOR=#F1F2F3]:[/COLOR][COLOR=#F1F2F3]\BatchPlayground[/COLOR][COLOR=#F1F2F3]>[/COLOR][COLOR=#93C763]set[/COLOR][COLOR=#F1F2F3] I[/COLOR][COLOR=#F1F2F3]=[/COLOR][COLOR=#F1F2F3]B[/COLOR][COLOR=#F1F2F3]:[/COLOR][COLOR=#F1F2F3]\CmdBrainStorming\NonExistantFile[/COLOR][COLOR=#F1F2F3].[/COLOR][COLOR=#F1F2F3]doh

C[/COLOR][COLOR=#F1F2F3]:[/COLOR][COLOR=#F1F2F3]\BatchPlayground[/COLOR][COLOR=#F1F2F3]>[/COLOR][COLOR=#F1F2F3]echo [/COLOR][COLOR=#F1F2F3]%~[/COLOR][COLOR=#F1F2F3]xI
doh

C[/COLOR][COLOR=#F1F2F3]:[/COLOR][COLOR=#F1F2F3]\BatchPlayground[/COLOR][COLOR=#F1F2F3]>[/COLOR][/FONT][/COLOR]


I hope this example helps further illustrate what i am trying to do.
Not too much more i can remove to make this problem easier to understand for others.
Note i use %~nx0 in the beginning. and it works. but i use %~xI later and it does not.





....::::some time later::::....




I got some help on this one from the people on "https://www.tenforums.com/" "Das10", and "garlin" weighed in with examples i was able to gleam a lot from. Here is the answer to the above problems i was having.
Code:
 @[URL="https://www.sevenforums.com/members/echo.html"]echo[/URL] Off
echo %~nx0 running.
set uhray[0]=A:\BatchPlayground\NoFile.exe
set uhray[1]=B:\CmdBrainStorming\NonExistantFile.doh
SETLOCAL ENABLEDELAYEDEXPANSION 
set z=0
:SymLoop
    if defined uhray[%z%] (
    For %%a in (!uhray[%z%]!) do (
        echo %%~xa
        )
    set /a "z+=1"
    GOTO :SymLoop
)
set z=
ENDLOCAL

And this version below, is an example using an array with it.
Of course we could just use a shortcut and use %1 %2 %3 %4 and so on to kill a list of files.
but for practice and for my ease of use and access to the files innards.
I am pleased with the array version used here, to close programs Sets, that are hanging or frozen in some way.
I run these files from the task manager when task-manager is all i can access. and it ends the software listed in the arrays. forcibly.

in this case, Grounded.exe and Maine-Win64-Shipping.exe

Code:
 [USER=353699]echo[/USER] off
echo %~nx0 running.
set uhray[0]=C:\Games\utilities\Steam\steamapps\common\Grounded\Grounded.exe
set uhray[1]=C:\Games\utilities\Steam\steamapps\common\Grounded\Maine\Binaries\Win64\Maine-Win64-Shipping.exe
SETLOCAL ENABLEDELAYEDEXPANSION
set debug=true
set z=0
:SymLoop
    if defined uhray[%z%] (
    For %%a in (!uhray[%z%]!) do (
        if %debug% equ true echo operating on uhray[%z%] containing: %%a
rem     echo full path name and extension  %%a
rem     echo %%~pa
rem     echo %%~na
rem     echo %%~xa
rem     echo name and extension: %%~nx

        if %debug% equ true echo @Taskkill
        Taskkill /T /F /IM "%%~nxa" > nul
        Taskkill /T /F /IM "%%a" > nul
        Taskkill /T /F /IM "%%~pa" > nul
        if %debug% equ true echo @wmic
rem     wmic process where "name='%%a'" delete > nul     Error: description = invalid query
        wmic process where "name='%%~nxa'" delete > nul
        if %debug% equ true echo @task_List-Find-Kill
        set "$process=%%~nxa*"
        for %%b in (%$process%) do tasklist >nul | find "%%b" && taskkill /F /IM %%b /T > nul
        if %debug% equ true echo [USER=337903]kIll[/USER]ed
        echo.   
        echo %%~na should be closed now.
        echo.
        echo.
        echo.
        echo.
        )
    
    set /a "z+=1"
    GOTO :SymLoop
)
set z=
set "$process="
ENDLOCAL
echo %~nx0 closing in 10 seconds.
Timeout /T 10 >NUL

Problem [SOLVED]

Ty for any input offered along this path from everyone across multiple forums.
 
Last edited:

My Computers

System One System Two

  • Computer type
    PC/Desktop
    Computer Manufacturer/Model Number
    Custom
    OS
    Windows 7 Ultimate x64
    CPU
    i7 990x
    Motherboard
    ASUS E6356_P6X58-E_Pro
    Memory
    48GB DDR3 RAM @1600MHZ 9-9-9-24 CL9
    Graphics Card(s)
    Sea Hawk NVIDIA GeForce GTX 1080 HD
    Hard Drives
    YES
    Antivirus
    NotTelling
    Browser
    Varies
  • Computer type
    PC/Desktop
Have a look here.


I don't wear a beanie, don't hardly wear a hat at all...
 

My Computer

Computer type
PC/Desktop
OS
Windows 7 Ultimate x64
I appreciate the reminder of the differences between my variables and the ones assigned to command line parameters. but that does not solve the code issue noted above. it just illustrates my problem.
 

My Computers

System One System Two

  • Computer type
    PC/Desktop
    Computer Manufacturer/Model Number
    Custom
    OS
    Windows 7 Ultimate x64
    CPU
    i7 990x
    Motherboard
    ASUS E6356_P6X58-E_Pro
    Memory
    48GB DDR3 RAM @1600MHZ 9-9-9-24 CL9
    Graphics Card(s)
    Sea Hawk NVIDIA GeForce GTX 1080 HD
    Hard Drives
    YES
    Antivirus
    NotTelling
    Browser
    Varies
  • Computer type
    PC/Desktop
Did you eve look at the whole website?
 

My Computer

Computer type
PC/Desktop
OS
Windows 7 Ultimate x64
just that page you linked. and i already had this one open before i commented here:
Batch Script - Arrays

as what im really working with is more complex then what i posted above.

maybe you could point me at something more specific im missing there please?
something that might actually be a direction rather then a bawd spectrum 'go read a book' ?

Maybe i made the example script too complex to follow,

Code:
[COLOR=#DBDEE1][FONT=Consolas]@[/FONT][/COLOR][COLOR=#FFA657][FONT=Consolas]echo[/FONT][/COLOR][COLOR=#DBDEE1][FONT=Consolas] Off
[/FONT][/COLOR][COLOR=#FFA657][FONT=Consolas]echo[/FONT][/COLOR][COLOR=#DBDEE1][FONT=Consolas] %~nx0 running.
[/FONT][/COLOR][COLOR=#FFA657][FONT=Consolas]set[/FONT][/COLOR][COLOR=#DBDEE1][FONT=Consolas] foo=C:\[/FONT][/COLOR][COLOR=#79C0FF][FONT=Consolas]1[/FONT][/COLOR][COLOR=#DBDEE1][FONT=Consolas]\[/FONT][/COLOR][COLOR=#79C0FF][FONT=Consolas]2[/FONT][/COLOR][COLOR=#DBDEE1][FONT=Consolas]\[/FONT][/COLOR][COLOR=#79C0FF][FONT=Consolas]3[/FONT][/COLOR][COLOR=#DBDEE1][FONT=Consolas]\[/FONT][/COLOR][COLOR=#79C0FF][FONT=Consolas]4[/FONT][/COLOR][COLOR=#DBDEE1][FONT=Consolas]\batch peramiter\substitution\wont\work\any\[/FONT][/COLOR][COLOR=#FFA657][FONT=Consolas]more[/FONT][/COLOR][COLOR=#DBDEE1][FONT=Consolas]\damnit.exe
[/FONT][/COLOR][COLOR=#FF7B72][FONT=Consolas]for[/FONT][/COLOR][COLOR=#DBDEE1][FONT=Consolas] /l [/FONT][/COLOR][COLOR=#79C0FF][FONT=Consolas]%%I [/FONT][/COLOR][COLOR=#FF7B72][FONT=Consolas]in[/FONT][/COLOR][COLOR=#DBDEE1][FONT=Consolas] ([/FONT][/COLOR][COLOR=#79C0FF][FONT=Consolas]1[/FONT][/COLOR][COLOR=#DBDEE1][FONT=Consolas],[/FONT][/COLOR][COLOR=#79C0FF][FONT=Consolas]1[/FONT][/COLOR][COLOR=#DBDEE1][FONT=Consolas],[/FONT][/COLOR][COLOR=#79C0FF][FONT=Consolas]1[/FONT][/COLOR][COLOR=#DBDEE1][FONT=Consolas]) [/FONT][/COLOR][COLOR=#FF7B72][FONT=Consolas]do [/FONT][/COLOR][COLOR=#FFA657][FONT=Consolas]echo [/FONT][/COLOR][COLOR=#79C0FF][FONT=Consolas]%%~[/FONT][/COLOR][COLOR=#DBDEE1][FONT=Consolas]n%foo%
[/FONT][/COLOR]

--------expected output:-------------------
C:\BatchPlayground>"C:\BatchPlayground\Substitutetutelage.bat"
Substitutetutelage.bat running.
damnit

C:\BatchPlayground>

--------received output:-------------------
C:\BatchPlayground>"C:\BatchPlayground\Substitutetutelage.bat"
Substitutetutelage.bat running.
%~nC:\1\2\3\4\batch peramiter\substitution\won't\work\any\more\damnit.exe

C:\BatchPlayground>





PS: post formatting on this site -hates me- like, all the way.. like 12 edits later and i get the formatting looking.. acceptabl'ish.. sorta hates me. RIP.


- - - Updated - - -

here is a non FOR based example of what im trying to do and expecting to see.:
Code:
 @[URL="https://www.sevenforums.com/members/echo.html"]echo[/URL] Off
echo %~nx0 running.
set uhray[0]=A:\BatchPlayground\NoFile.exe
set uhray[1]=B:\CmdBrainStorming\NonExistantFile.doh
set uhray[2]=C:\SomeOtherPlace\FictionalFile.lalala
SETLOCAL enableextensions 
set z=0
:SymLoop
if defined uhray[%z%] (
    set q=%uhray[%z%]%
    call echo %%~xq
    set /a "z+=1"
    GOTO :SymLoop
)
set z=
ENDLOCAL

result:
C:\BatchPlayground>C:\BatchPlayground\Substitutetutelage2.bat
Substitutetutelage2.bat running.
The following usage of the path operator in batch-parametersubstitution is invalid: %~xq
For valid formats type CALL /? or FOR /?
The following usage of the path operator in batch-parametersubstitution is invalid: %~xq
For valid formats type CALL /? or FOR /?
The following usage of the path operator in batch-parametersubstitution is invalid: %~xq
For valid formats type CALL /? or FOR /?

C:\BatchPlayground>

Expected result:
C:\BatchPlayground>C:\BatchPlayground\Substitutetutelage2.bat
Substitutetutelage2.bat running.
exe
doh
lalala

C:\BatchPlayground>
 
Last edited:

My Computers

System One System Two

  • Computer type
    PC/Desktop
    Computer Manufacturer/Model Number
    Custom
    OS
    Windows 7 Ultimate x64
    CPU
    i7 990x
    Motherboard
    ASUS E6356_P6X58-E_Pro
    Memory
    48GB DDR3 RAM @1600MHZ 9-9-9-24 CL9
    Graphics Card(s)
    Sea Hawk NVIDIA GeForce GTX 1080 HD
    Hard Drives
    YES
    Antivirus
    NotTelling
    Browser
    Varies
  • Computer type
    PC/Desktop
Post this to the tenforums here or Stack Exchange. At tenforums there are a couple users that know more batch code than I do.
 

My Computer

Computer type
PC/Desktop
OS
Windows 7 Ultimate x64
Thank you. i shall do so.

I've condensed the present experiment down to the following, just to grasp array declaration and usage, as well as
EnableDelayedExpansion allowing me to see the changes as the (not a FOR) loop iterates,
which also altered the way the vars were encased.
It still does not work as expected. But, the array iteration is at least visible.

[code echo Offecho %~nx0 running.


set uhray[0]=A:\BatchPlayground\NoFile.exe
set uhray[1]=B:\CmdBrainStorming\NonExistantFile.doh
set uhray[2]=C:\SomeOtherPlace\FictionalFile.lalala
SETLOCAL ENABLEDELAYEDEXPANSION
set z=0
:SymLoop
if defined uhray[%z%] (
echo uhray[%z%]= !uhray[%z%]!
echo %%~x!uhray[%z%]!
set /a "z+=1"
GOTO :SymLoop
)
set z=
ENDLOCAL

REM .
REM .
REM .
REM everything below here causes a substitution invalid error in the script even when its in a REMARK. @,@?
REM echo %%~x!uhray[%z%]!
REM set q=%uhray[!z!]%...
REM call echo %%~xq
REM echo %%~x!uhray[%z%]!
REM call echo %~x!uhray[%z%]!
REM call echo %%~x!uhray[%z%]!
REM set Q=!uhray[%z%]!
REM echo %%~x%Q%[/code]

Output:
Code:
C:\BatchPlayground>C:\BatchPlayground\Substitutetutelage2.bat
Substitutetutelage2.bat running.
uhray[0]= A:\BatchPlayground\NoFile.exe
%~xA:\BatchPlayground\NoFile.exe
uhray[1]= B:\CmdBrainStorming\NonExistantFile.doh
%~xB:\CmdBrainStorming\NonExistantFile.doh
uhray[2]= C:\SomeOtherPlace\FictionalFile.lalala
%~xC:\SomeOtherPlace\FictionalFile.lalala
The following usage of the path operator in batch-parameter
substitution is invalid: %~x!uhray[%z%]!


For valid formats type CALL /? or FOR /?
The syntax of the command is incorrect.

C:\BatchPlayground>

Expected Output:
Code:
C:\BatchPlayground>C:\BatchPlayground\Substitutetutelage2.bat
Substitutetutelage2.bat running.
uhray[0]= A:\BatchPlayground\NoFile.exe
exe
uhray[1]= B:\CmdBrainStorming\NonExistantFile.doh
doh
uhray[2]= C:\SomeOtherPlace\FictionalFile.lalala
lalala

C:\BatchPlayground>

Its now on the TenForum,

I've posted this problem over on "stack overflow" too. but immediately got downvoted into oblivion for not knowing batch code.

i mean.. that is kinda the point, if your asking for help, your admitting you need help learning it better. Maybe its just troll'y over there.

TLDR: trying to get var.expansion/substitution operational with array Vars, and not just the typical %1 %2 %3 it seems to be restricted to.
The definitions for things like %~n and %~nx and %%~p are inside the FOR /? help sheet oddly enough. Though they can clearly be used without a CALL or FOR itself.

Please assist?

.
.
.
.
:::some time later:::
.
.
.
.



The same problem exists even if i don't use an array for the var.
Code:
echo %~nx0 running.
set I=B:\CmdBrainStorming\NonExistantFile.doh
echo %~xI


Output:
Code:
C:\BatchPlayground>C:\BatchPlayground\Substitutetutelage3.bat


C:\BatchPlayground>echo Substitutetutelage3.bat running.
Substitutetutelage3.bat running.


C:\BatchPlayground>set I=B:\CmdBrainStorming\NonExistantFile.doh
The following usage of the path operator in batch-parameter
substitution is invalid: %~xI




For valid formats type CALL /? or FOR /?


C:\BatchPlayground>echo %~xI


C:\BatchPlayground>


Expected Output:
Code:
C:\BatchPlayground>C:\BatchPlayground\Substitutetutelage3.bat


C:\BatchPlayground>echo Substitutetutelage3.bat running.
Substitutetutelage3.bat running.


C:\BatchPlayground>set I=B:\CmdBrainStorming\NonExistantFile.doh


C:\BatchPlayground>echo %~xI
doh


C:\BatchPlayground>


I hope this example helps further illustrate what i am trying to do.
Not too much more i can remove to make this problem easier to understand for others.
Note i use %~nx0 in the beginning. and it works. but i use %~xI later and it does not.




....::::some time later::::....




I got some help on this one from the people on "https://www.tenforums.com/" "Das10", and "garlin" weighed in with examples i was able to gleam a lot from. Here is the answer to the above problems i was having.
Code:
 @[URL="https://www.sevenforums.com/members/echo.html"]echo[/URL] Off
echo %~nx0 running.
set uhray[0]=A:\BatchPlayground\NoFile.exe
set uhray[1]=B:\CmdBrainStorming\NonExistantFile.doh
SETLOCAL ENABLEDELAYEDEXPANSION
set z=0
:SymLoop
    if defined uhray[%z%] (
    For %%a in (!uhray[%z%]!) do (
        echo %%~xa
        )
    set /a "z+=1"
    GOTO :SymLoop
)
set z=
ENDLOCAL

And this version below, is an example using an array with it.
Of course we could just use a shortcut and use %1 %2 %3 %4 and so on to kill a list of files.
but for practice and for my ease of use and access to the files innards.
I am pleased with the array version used here, to close programs Sets, that are hanging or frozen in some way.
I run these files from the task manager when task-manager is all i can access. and it ends the software listed in the arrays. forcibly.

in this case, Grounded.exe and Maine-Win64-Shipping.exe

Code:
 [USER=353699]echo[/USER] off
echo %~nx0 running.
set uhray[0]=C:\Games\utilities\Steam\steamapps\common\Grounded\Grounded.exe
set uhray[1]=C:\Games\utilities\Steam\steamapps\common\Grounded\Maine\Binaries\Win64\Maine-Win64-Shipping.exe
SETLOCAL ENABLEDELAYEDEXPANSION
set debug=true
set z=0
:SymLoop
    if defined uhray[%z%] (
    For %%a in (!uhray[%z%]!) do (
        if %debug% equ true echo operating on uhray[%z%] containing: %%a
rem     echo full path name and extension  %%a
rem     echo %%~pa
rem     echo %%~na
rem     echo %%~xa
rem     echo name and extension: %%~nx

        if %debug% equ true echo @Taskkill
        Taskkill /T /F /IM "%%~nxa" > nul
        Taskkill /T /F /IM "%%a" > nul
        Taskkill /T /F /IM "%%~pa" > nul
        if %debug% equ true echo @wmic
rem     wmic process where "name='%%a'" delete > nul     Error: description = invalid query
        wmic process where "name='%%~nxa'" delete > nul
        if %debug% equ true echo @task_List-Find-Kill
        set "$process=%%~nxa*"
        for %%b in (%$process%) do tasklist >nul | find "%%b" && taskkill /F /IM %%b /T > nul
        if %debug% equ true echo [USER=337903]kIll[/USER]ed
        echo.  
        echo %%~na should be closed now.
        echo.
        echo.
        echo.
        echo.
        )
    
    set /a "z+=1"
    GOTO :SymLoop
)
set z=
set "$process="
ENDLOCAL
echo %~nx0 closing in 10 seconds.
Timeout /T 10 >NUL

Problem [SOLVED]

Ty for any input offered along this path from everyone across multiple forums.
 
Last edited:

My Computers

System One System Two

  • Computer type
    PC/Desktop
    Computer Manufacturer/Model Number
    Custom
    OS
    Windows 7 Ultimate x64
    CPU
    i7 990x
    Motherboard
    ASUS E6356_P6X58-E_Pro
    Memory
    48GB DDR3 RAM @1600MHZ 9-9-9-24 CL9
    Graphics Card(s)
    Sea Hawk NVIDIA GeForce GTX 1080 HD
    Hard Drives
    YES
    Antivirus
    NotTelling
    Browser
    Varies
  • Computer type
    PC/Desktop
Yeah, Stack Exchange and its other websites are abhorrently hostel like that with the thumbs down horseshit. I've had that happen to be a million times and I was like you: "why? I'm asking a f^&&king question. Isn't that why this site exists in the first place?" Voter ability on the Internet is massively overused (and abused)... Yet, I see many other questions not down voted. So, sometimes your question is answered and sometimes your question is down voted by all the low IQ bipedal chimps. Good information there though. I use them many times trying to figure things out. However, very mundane and easy to answer questions are prevalent and it begs the question why my, yours or other questions are down voted into oblivion. I've also saw other shenanigans. In one instance, the Stack Exchange account belonging to the DuckDuckGo founder has loads of BS awards and crap and yet he's only answered maybe two or three questions if that. I have a screenshot just in case it's changed or removed. In another instance I think they censor like a bitch for certain posters. So, like Twitter, YouStupid (YouTube), Facebook, Google and all the rest of the Nazi's, they all circlejerk one another so hard you can see it.

Sorry Stack Exchange or one of its websites didn't work out. I thought it would because I saw LOADS of very complex batch code questions asked there. Many of which helped me out. But! At tenforums you should get some responses. I can't remember the username for the life of me, but he's like a batch code freak. LOL
 

My Computer

Computer type
PC/Desktop
OS
Windows 7 Ultimate x64
Back
Top