I want to get the filename from a filepath. My problem is, that I found many solutions for handling it with input via parameters. But I want to use a userinput instead of a parameter.
The soultion for parameters is:
%~nxI //I could be number for the parameter count
My script actually looks like this:
@echo off
set /p path=Film:
echo %path2%
pause
Now I want to get the filename + extension from %path% and write it to %path2%.
Could anyone help me please?
set /p x=Film:
echo %x%
for %%F in (%x%) do set q=%%~nF
echo %q%
...and for Pete's sake do not prompt the user to set the PATH variable! use some other variable name!
an alternative, instead of using FOR, that may be useful in some situations, is to substitute the variable passing the values as parameters in a CALL.
call :extractfn %x% q
echo %q%
goto :eof
:extractfn
set %2=%~n1
goto :eof
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With