如何做一个“目录"output.txt"仅在选定的文件上 [英] How to do a "dir > output.txt" on selected files only

查看:54
本文介绍了如何做一个“目录"output.txt"仅在选定的文件上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过批处理文件在资源管理器中选择多个文件,然后将其名称(仅名称,文件夹中的每个文件都没有)写入文本文件?谢谢.

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.

推荐答案

是的,这是可能的.使用以下批处理代码:

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%"
)

在每次执行批处理文件时,始终将创建的活动用户桌面上具有所选文件路径的文件名写入名称为 FileNames.txt 的文件中.

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.

创建此批处理文件后,在目录%USERPROFILE%\ SentTo 中创建此批处理文件的快捷方式,并在快捷方式的属性中指定以始终在最小化的控制台窗口下运行该批处理文件.

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.

那么有可能

  • 在Windows资源管理器中选择文件,
  • 右键单击所选文件之一,然后
  • 使用发送至子菜单
  • 中的上下文菜单项(快捷方式名称)
  • select files in Windows Explorer,
  • right click on one of the selected files and
  • use the context menu item (name of shortcut) in Sent To submenu

将所选文件的名称带有路径写入文本文件.

to write the names of the selected files with path into the text files.

要仅获取文件名(不含路径),请将第6行更改为:

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.

  • 呼叫/?
    解释%〜1 -第一个参数不带双引号-和%〜nx1 -仅第一个参数的名称和文件扩展名不带双引号.
  • echo/?
  • 转到/?
  • 如果/?
  • shift/?
  • 排序/?
  • call /?
    Explains %~1 - first argument without double quotes - and %~nx1 - just name and file extension of first argument without double quotes.
  • echo /?
  • goto /?
  • if /?
  • shift /?
  • sort /?

并阅读有关使用命令重定向操作符的Microsoft文章.

And read also Microsoft article about Using command redirection operators.

注意:

命令行的长度受到限制,因此它不是可以选择几千个文件,并将其文件名连同完整路径发送到批处理文件.Windows资源管理器仅运行批处理文件,并且在调用该批处理文件时将每个文件名指定为参数.

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.

顺便说一句:

我最喜欢的文件管理器Total Commander内置了以下命令:

My favorite file manager Total Commander has built-in the commands:

  • cm_CopyNamesToClip
    如果没有选择没有路径到剪贴板,则复制所选文件/文件夹的文件/文件夹名称或光标下的文件/文件夹.
  • cm_CopyFullNamesToClip
    如果没有选择具有完整路径的剪贴板,则将所选文件/文件夹的文件/文件夹名称复制到光标下的文件/文件夹.
  • cm_CopyNetNamesToClip
    如果没有选择具有完整UNC路径的剪贴板,则将所选文件/文件夹的文件/文件夹名称复制到光标下的文件/文件夹名称.
  • cm_CopyNamesToClip
    Copies the file/folder names of the selected files/folders or the file/folder under cursor if nothing selected without path to clipboard.
  • cm_CopyFullNamesToClip
    Copies the file/folder names of the selected files/folders or the file/folder under cursor if nothing selected with full path to clipboard.
  • cm_CopyNetNamesToClip
    Copies the file/folder names of the selected files/folders or the file/folder under cursor if nothing selected with full UNC path to clipboard.

我为TC的三个命令分别分配了一个热键,并将它们也添加到TC的工具栏,以便随时通过键盘或鼠标单击快速执行.这是由我15年前完成的,从那时起,我再也没有手动键入已经存在的文件的文件名.在Total Commander中使用这3个命令时,文件/文件夹的数量没有限制.

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.

这篇关于如何做一个“目录"output.txt"仅在选定的文件上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆