FriendFX
FriendFX

Reputation: 3079

Convert list of paths to list of filenames

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?

Upvotes: 3

Views: 302

Answers (2)

dbenham
dbenham

Reputation: 130839

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

Upvotes: 1

Monacraft
Monacraft

Reputation: 6620

Couldn't you just:

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

Upvotes: 0

Related Questions