开发者

receiving only the filename in a shell command

开发者 https://www.devze.com 2023-04-10 03:10 出处:网络
I want to get only the filename (and no the full path) when running a shell command on some file extension (In the context menu of it)

I want to get only the filename (and no the full path) when running a shell command on some file extension (In the context menu of it) It is probably done somehow in the registry, in the file extension under HKCR. Any of %1 %l %L gives the full path. I want only the filename

thanks


The idea is good, but I can't make it work

I created the file- GetFileName.bat I put it somewhere it is in the%path%

it looks like that: @set Ret="%~n1"

and in the registry I put the following command

cmd /k GetFileName "%L" & hh.exe -decompile extracted %Ret%

which means: * Run this- GetFileName "%L" * a开发者_JAVA技巧nd then- hh.exe -decompile extracted %Ret%

but the %Ret% doesn't give me the result of the GetFileName, although it contains the environment variable Ret with the correct value.

I guess it doesn't allow in the registry to use this environment variable because it is in the same line


You can use the %~n modifier to extract a filename from a path in a script argument, but it does not appear to recognize other environment varaibles, so you'll have to stuff it into a separate batch file:

getext.bat:

@set Ret=%~n1

and then

C:\> getext hello.bat
C:\> echo %Ret%
hello
0

精彩评论

暂无评论...
验证码 换一张
取 消