批处理文件到列表文件的路径和文件名,在CSV [英] Batch file to list file path and file name in a csv
问题描述
我试图做一个批处理文件,列出文件夹中的和子董事及出口与文件大小CSV中的所有文件,我有curently有这样的:
I am trying to make a batch file that lists all files in in a folder and sub directors and exports to a csv with file size, I curently have this:
@ECHO OFF &SETLOCAL
(FOR /f "delims=|" %%a IN ('dir /s /b /a-d') DO (
FOR /f "tokens=1-9*" %%x IN ('dir /b /a-d /tc "%%~a"^| C:\Windows\System32\findstr "^[0-9]"') DO (
ECHO %%a, %%z
)
))>DIR.csv
TYPE DIR.csv
但我需要的是文件目录,并作为单独的记录文件路径
But what I need is the File directory and File path as separate records
推荐答案
这可以通过命令行一个简单的直接班轮完成的 - 没有批量要求
This can be accomplished with a simple one liner directly from the command line - no batch required.
文件名可以包含逗号,所以他们应该在您的CSV报价。下面将创建一个文件路径,文件名,文件大小,每行一个CSV文件。
File names can contain comma, so they should be quoted in your CSV. The following will create a csv with file path, file name, file size on each line.
(for /r %F in (*) do @echo "%~dpF","%~nxF",%~zF) >dir.csv
如果一个批处理脚本中使用折起来百分比。
Double up the percents if used within a batch script.
键入的帮助
或 FOR /?
从文档的命令行FOR命令。在底部是所有可以FOR变量值扩大一个时所使用的改性剂的描述
Type HELP FOR
or FOR /?
from the command line for documentation on the FOR command. At the bottom is a description of all of the modifiers that can be used when expanding a FOR variable value.
这篇关于批处理文件到列表文件的路径和文件名,在CSV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!