3

Background

I find myself often copying file paths to the clipboard, which is somewhat cumbersome to do from Windows Explorer.

So I wrote a little .bat file to put into the %APPDATA%\Microsoft\Windows\SendTo\ folder utilising the CLIP executable to copy a list of the selected file paths to the clipboard. This file consists only of a single line:

echo|set /p= "%*" | clip.exe

Which works quite nicely, I can select one or more filenames in Explorer, right-click on them and "Send To" the .bat file, which copies them to the clipboard. Each file path is complete and separated from the others by a space character.

Question

Sometimes, I don't want to copy a list of the full file paths, but would prefer to have a list of just the filenames with their extensions. I know how to do that conversion for single file paths, using the %~nx syntax as described here or here.

I tried different combinations of these but can't seem to find a workable solution for my list of paths. The following code echos the filenames correctly:

for %%F in (%*) do echo %%~nxF

...but how do I combine them to pass through to CLIP? Do I have to do string concatenation? Maybe in a subroutine to be called, or is there a more elegant solution?

FriendFX
  • 2,929
  • 1
  • 34
  • 63

2 Answers2

1

The following will put each file name on a separate line within the clipboard:

@(for %%F in (%*) do @echo %%~nxF)|clip

If you prefer, the following will put a space delimited list of file names on a single line, with quotes around each file name.

@(for %%F in (%*) do @<nul set /p =""%%~nxF" ")|clip
dbenham
  • 127,446
  • 28
  • 251
  • 390
0

Couldn't you just:

echo|set /p= "%~nx*" | clip.exe
Monacraft
  • 6,510
  • 2
  • 17
  • 29