Reputation: 75
Is it possible via batch file to take select multiple files in Explorer and write their names (and their names only; not every file in the folder) to a text file? Thanks.
Upvotes: 2
Views: 1599
Reputation: 49136
Yes, this is possible. Use following batch code:
@echo off
set "OutputFile=%USERPROFILE%\Desktop\FileNames.txt"
del "%OutputFile%" 2>nul
:NextFileName
if not "%~1" == "" (
echo %~1>>"%OutputFile%"
shift
goto NextFileName
)
if exist "%OutputFile%" (
%SystemRoot%\System32\sort.exe "%OutputFile%" /O "%OutputFile%"
)
The file names with path of the selected files are written to a file with name FileNames.txt
on desktop of active user always created new on each execution of the batch file.
After creating this batch file, create a shortcut to this batch file in directory %USERPROFILE%\SentTo
and specify in properties of the shortcut to run the batch file always with minimized console window.
Then it is possible to
to write the names of the selected files with path into the text files.
To get just the names of the files without path, change line 6 to:
echo %~nx1>>"%OutputFile%"
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
call /?
%~1
- first argument without double quotes - and %~nx1
- just name and file extension of first argument without double quotes.echo /?
goto /?
if /?
shift /?
sort /?
And read also Microsoft article about Using command redirection operators.
Note:
The length of a command line is limited and therefore it is not possible to select several thousand files and send their file names with full path to the batch file. Windows Explorer runs simply the batch file with each file name being specified as parameter on calling the batch file.
By the way:
My favorite file manager Total Commander has built-in the commands:
cm_CopyNamesToClip
cm_CopyFullNamesToClip
cm_CopyNetNamesToClip
I assigned a hotkey to each of the 3 commands of TC and added them also to toolbar of TC for quick execution at any time by keyboard or mouse click. This was done by me more than 15 years ago and since then I have never typed manually a file name for a file already existing. There is no limitation on number of files/folders on using those 3 commands in Total Commander.
Upvotes: 5