[英]Copy file paths using .bat file into a txt file
How can I use a .bat file to copy only the file paths from a directory? 如何使用.bat文件仅复制目录中的文件路径?
For example, I have a folder with 1000 files in it. 例如,我有一个包含1000个文件的文件夹。 I need a full UNC path for each file put into a text file.
对于放入文本文件的每个文件,我都需要完整的UNC路径。 This would include the file extension well.
这将很好地包括文件扩展名。
Copy only the file paths: 仅复制文件路径:
(for %a in (*.*) do @echo %~DPa) > output.txt
Copy file paths with extensions: 复制带有扩展名的文件路径:
(for %a in (*.*) do @echo %~DPXa) > output.txt
Previous are command-lines; 上一个是命令行。 you may include they in a Batch file, if you wish.
如果需要,可以将它们包含在批处理文件中。
It's always surprised me that the DIR command doesn't have an option to display the full path of the files. DIR命令没有显示文件完整路径的选项,这总是让我感到惊讶。 Anyway, here's a VBScript solution:
无论如何,这是一个VBScript解决方案:
With CreateObject("Scripting.FileSystemObject")
Set Out = .CreateTextFile("c:\text.txt", True)
For Each File In .GetFolder("c:\some_folder").Files
Out.WriteLine File.Path
Next
Out.Close
End With
~f
modifier ~f
修饰符获取完整路径 for /f "delims=" %A in ('dir /a-d/b') do @echo %~fA >> list.txt
Note: Remember to double those percents if using inside a batch file. 注意:如果在批处理文件中使用,请记住将这些百分比加倍。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.