Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
celsius
- Posts: 11
- Joined: 05 Feb 2020 01:27
#1
Post
by celsius » 05 Feb 2020 01:41
Hi, Greetings to all users of this forum
I need help to modify this command
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
-
ShadowThief
- Expert
- Posts: 1160
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
#2
Post
by ShadowThief » 05 Feb 2020 06:32
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
to get the filename
-
celsius
- Posts: 11
- Joined: 05 Feb 2020 01:27
#3
Post
by celsius » 05 Feb 2020 06:50
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
-
jeb
- Expert
- Posts: 1041
- Joined: 30 Aug 2007 08:05
- Location: Germany, Bochum
#4
Post
by jeb » 05 Feb 2020 08:09
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
-
celsius
- Posts: 11
- Joined: 05 Feb 2020 01:27
#5
Post
by celsius » 05 Feb 2020 08:43
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
-
celsius
- Posts: 11
- Joined: 05 Feb 2020 01:27
#7
Post
by celsius » 05 Feb 2020 10:45
Yes, it works well as context menu. Again, as button, the variable is not expanded
-
Squashman
- Expert
- Posts: 4465
- Joined: 23 Dec 2011 13:59
#8
Post
by Squashman » 05 Feb 2020 10:52
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.
-
celsius
- Posts: 11
- Joined: 05 Feb 2020 01:27
#9
Post
by celsius » 05 Feb 2020 11:18
In my last attempts, I also tried
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
-
penpen
- Expert
- Posts: 1991
- Joined: 23 Jun 2013 06:15
- Location: Germany
#10
Post
by penpen » 06 Feb 2020 05:52
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
-
celsius
- Posts: 11
- Joined: 05 Feb 2020 01:27
#11
Post
by celsius » 06 Feb 2020 13:03
Thanks,
Unfortunately it doesn't work
-
Eureka!
- Posts: 136
- Joined: 25 Jul 2019 18:25
#12
Post
by Eureka! » 06 Feb 2020 18:15
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" ....
-
celsius
- Posts: 11
- Joined: 05 Feb 2020 01:27
#13
Post
by celsius » 06 Feb 2020 19:28
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
-
Eureka!
- Posts: 136
- Joined: 25 Jul 2019 18:25
#14
Post
by Eureka! » 06 Feb 2020 20:30
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)
-
celsius
- Posts: 11
- Joined: 05 Feb 2020 01:27
#15
Post
by celsius » 06 Feb 2020 22:42
Thanks!!!
I'm very happy
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)