Page 1 of 2

Copy name

Posted: 05 Feb 2020 01:41
by celsius
Hi, Greetings to all users of this forum

I need help to modify this command

Code: Select all

cmd /c echo|set /p="%2"|clip
It copies full path of the selected file, I'd like instead coping only the name without extension
I know this is an elementary request, I'm sorry but, please, be patient

Re: Copy name

Posted: 05 Feb 2020 06:32
by ShadowThief
Variable expansion for filename manipulation is hidden in the output of for /? for some reason, but if you manage to find it you'll see that you can use

Code: Select all

cmd /c echo|set /p="%~n2"|clip
to get the filename

Re: Copy name

Posted: 05 Feb 2020 06:50
by celsius
Thanks,
Unfortunately in my case this solution doesn't work. It is copied only %~n2
I tried the for variable output, but as now, only the variable is copied and not the filename

Re: Copy name

Posted: 05 Feb 2020 08:09
by jeb
Hi celsius,

is it possible that your command is bound to the context menu of the explorer?
And your command is stored in the registry?

I'm only guessing, but when "%~n2" doesn't expand, that's an obvious possibility.

jeb

Re: Copy name

Posted: 05 Feb 2020 08:43
by celsius
I'd like to create a button in the explorer toolbar of Open-Shell that allows me to copy the name of the selected file.
I was able to copy only the full path

Re: Copy name

Posted: 05 Feb 2020 10:02
by Squashman
Look at Context Menu options using CMD.exe or Powershell
In my first example it would be extremely easy to change it from copying the file path to just the file name.

Re: Copy name

Posted: 05 Feb 2020 10:45
by celsius
Yes, it works well as context menu. Again, as button, the variable is not expanded

Re: Copy name

Posted: 05 Feb 2020 10:52
by Squashman
celsius wrote:
05 Feb 2020 10:45
Yes, it works well as context menu. Again, as button, the variable is not expanded
Then you are going to have to work with the developer of Open Shell.

Re: Copy name

Posted: 05 Feb 2020 11:18
by celsius
In my last attempts, I also tried

Code: Select all

cmd /c echo|set /p="%1"|clip
In this way is it copied the path without the filename. I tried 0 4 5 without luck
Also, I realized that in these cases and in your suggestions is it copied nothing. The clipboard content didn't change

Re: Copy name

Posted: 06 Feb 2020 05:52
by penpen
I used something similar for a link in the win10 "sendto" menue - but i don't know if that also works for buttons in openshell, so the following might or might not help you:

Code: Select all

%comspec% /V:ON /E:ON /c @for %n in (1 2) do @if %n == 2 (if defined params for %b in (!params!) do @call <nul set/p= "%~nb" | clip) else set params=
penpen

Re: Copy name

Posted: 06 Feb 2020 13:03
by celsius
Thanks,
Unfortunately it doesn't work

Re: Copy name

Posted: 06 Feb 2020 18:15
by Eureka!
So this OpenShell has it's own definitions of %1 (path of selected file) and %2 (fully qualified filename including path)?
And it doesn't understand things like %~2 and passes % it doesn't understand as % (instead of stripping it) ...

In that case, does this work for you?

Code: Select all

cmd.exe /c @for %x in ("%2") do @echo %~nx|clip

And please, provide better feedback than "It doesn't work" ....

Re: Copy name

Posted: 06 Feb 2020 19:28
by celsius
I get on internet the code I posted in my first post. I don't remember anymore what is the site. It's not related with OpenShell.
Even with your code there is nothing copied in the clipboard, its content isn't modified at all

Re: Copy name

Posted: 06 Feb 2020 20:30
by Eureka!
OK, downloaded OpenShell; broke open the installer and extracted the DLL responsible for the Explorer Toolbar; registered the DLL and tried my suggestion. I could see a CMD windows opening and closing very fast .. and that was it.

This does work (tested):

Code: Select all

%SystemRoot%\System32\cmd.exe  /c @for %%x in ("%2") do @echo %%~nx|clip
(It should be %% instead of % after all)

Re: Copy name

Posted: 06 Feb 2020 22:42
by celsius
Thanks!!!
I'm very happy :D :D :D

The last button I'd like to create is one that selects all files with the same extension of the already selected file. Do you think is possible through the command line?
Alternative I need to modify an Autohotkey script? (I know this is not the right forum, sorry)