Michael Walter
Michael Walter

Reputation: 63

Get Filename from Filepath

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?

Upvotes: 3

Views: 2382

Answers (2)

PA.
PA.

Reputation: 29369

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

Upvotes: 2

Mike Nakis
Mike Nakis

Reputation: 62169

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!

Upvotes: 4

Related Questions