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:
Output:
Expected Output:
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:
Output:
Expected Output:
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.
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
Problem [SOLVED]
Ty for any input offered along this path from everyone across multiple forums.
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