简体   繁体   English

使用批处理文件列出csv上的文件名和文件夹路径

[英]List filenames and folder paths on csv using batch file

I have a batch file that lists the full file directories (including filename at the end) onto a csv file. 我有一个批处理文件,其中列出了完整文件目录(末尾包括文件名)到csv文件中。 I need it to produce this, but also just the filename in a separate column. 我需要它来生成此文件,也需要它在单独的列中的文件名。 I would like it so that the format is Filename in first column (including extension) and full file directory in second column. 我希望它的格式为第一列(包括扩展名)为“文件名”,第二列为完整的文件目录。 The batch file I currently have is: 我当前拥有的批处理文件是:

dir C:\Users\Administrator\Desktop\test\Files\*.tif /b /s >>
C:\Users\Administrator\Desktop\test\Output.csv

EDIT: I forgot to mention the 'Files' folder contains many subfolders so I need it to process all files from all these subfolders. 编辑:我忘了提到“文件”文件夹包含许多子文件夹,因此我需要它来处理所有这些子文件夹中的所有文件。

Thanks in advance. 提前致谢。

You just need to do this: 您只需要这样做:

@echo off
setlocal

set "in=C:\Users\Administrator\Desktop\test\Files\*.tif"
set "out=C:\Users\Administrator\Desktop\test\Output.csv"

if not exist "%out%" type nul>"%out%"
for /f "delims=" %%a in ('dir /b/s %in%') do (
    >>%out% echo "%%~nxa","%%a"
)

Iterate and write ( help for for info on the %~ variable modifiers): 迭代并编写(有关%~变量修饰符的信息的help for ):

@echo off
cd C:\Users\Administrator\Desktop\test\Files
for %%f in (*.tif) do echo "%%~nxf","%%~dpf" >> Output.csv

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM