windows 批处理文件以搜索文件名并将其复制到新的 TXT 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3131596/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Batch file to search and copy file names to new TXT file
提问by user375191
I want to search *.cpp files in current directory and want to save the file name in *.TXT file. I did this by using the Batch command
我想在当前目录中搜索 *.cpp 文件并将文件名保存在 *.TXT 文件中。我是通过使用 Batch 命令完成的
dir |find ".cpp" > Listfile.txt
But there I am getting file name with entire paramenters like created date and size.
但是在那里我得到了带有整个参数的文件名,比如创建日期和大小。
My need is I want only file name
我的需要是我只想要文件名
Current output
06/25/2010 06:17 PM 950 4mLinuxMachine.cpp
06/28/2010 03:41 PM 4,236 Linux11.cpp
Need Output
4mLinuxMachine.cpp
Linux11.cpp
Please help Thanks
请帮忙谢谢
回答by Paul R
Try:
尝试:
dir /b | find ".cpp" > Listfile.txt
or better still:
或者更好:
dir /b *.cpp > Listfile.txt
回答by grebulon
Search from the file explorer and use this shell extension to copy from the context menu: http://grebulon.com/software/copylocation.php
从文件资源管理器中搜索并使用此 shell 扩展名从上下文菜单中复制:http: //grebulon.com/software/copylocation.php
"This shell extension adds the ability to copy file and folder names from the Windows Explorer window to the clipboard. Simply select the file(s) whose name you want to copy, right-click and select "Copy File Path" or "Copy File Name" from the context menu. Then paste to any editor. Copy File Path - copies the entire path to the file. Copy File Name - copies only the file name without the folder."
“此外壳扩展添加了将文件和文件夹名称从 Windows 资源管理器窗口复制到剪贴板的功能。只需选择要复制其名称的文件,右键单击并选择“复制文件路径”或“复制文件” “名称”。然后粘贴到任何编辑器。复制文件路径 - 将整个路径复制到文件。复制文件名 - 仅复制文件名而不复制文件夹。”
回答by pmod
Use bare format: dir /B
使用裸格式:dir /B
dir /B |find ".cpp" > Listfile.txt
Othe options you can find using:
您可以使用以下选项找到其他选项:
dir /?
回答by sarnold
If you don't mind installing or using cygwin tools, this task can be done like so:
如果你不介意安装或使用 cygwin 工具,这个任务可以这样完成:
find . -type f -name '*.cpp' -print > Listfile.txt