0

I'm using this script in the batch file I created to copy the filenames to clipboard then I can use,

@echo off
set dirpath=%1
dir %dirpath% /b /n | clip
exit

I created a shortcut in Windows SendTo menu that directed to this batch file. When I want to copy file names in a specific folder to clipboard, I just right click on this folder then SendTo this batch file. This works fine.

But can I improve this script by skipping the file extensions (like .jpg)?

Thanks for your help.

0

Simple solution using an auxiliary file:

@ECHO OFF
SETLOCAL EnableExtensions DisableDelayedExpansion

>"%temp%\%~n0.txt" (
    for /F "delims=" %%G in ('dir "%~1" /b') do echo(%%~nG
)
type "%temp%\%~n0.txt"|clip

rem erase "%temp%\%~n0.txt"

exit

For a solution without an auxiliary file, inspire yourself in Assigning newline character to a variable in a batch script

Resources (required reading):

  • Sorry for my late reply. But your solution worked like a charm. Thank you. Namo Amitabha. – Leigh Mar 16 '16 at 2:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.