仅在命令行中列出具有路径和文件大小的文件

List files with path and file size only in Command Line

Windows 命令行(或者可能是 PowerShell)。

如何以完整路径和文件大小递归地列出所有文件,但不包含任何其他内容并导出到 .txt 文件。最好是适用于我在命令行中的任何当前目录的代码(因此不需要手动输入目标目录)。

None 其中仅提供 path\filename 和文件大小:

dir /s > filelist.txt
dir /s/b > filelist.txt
dir /s/o:-d > filelist.txt

所需输出(fullpath\file.ext 文件大小):

c:\aaa\file.ext 7755777    
c:\aaa\bbb.txt 897667
c:\aaa\bbb.ext 67788990
c:\aaa\bbb\nnn\a.xls 99879000
Get-ChildItem -Recurse | select FullName,Length | Format-Table -HideTableHeaders | Out-File filelist.txt

PowerShell:

gci -rec -file|%{"$($_.Fullname) $($_.Length)"} >filelist.txt

早期的 PowerShell 版本:

gci -rec|?{!$_.PSIsContainer}|%{"$($_.Fullname) $($_.Length)"} >filelist.txt

批处理文件:

(@For /F "Delims=" %%A in ('dir /B/S/A-D') Do @Echo %%~fA %%~zA) >filelist.txt

命令行

(@For /F "Delims=" %A in ('dir /B/S/A-D') Do @Echo %~fA %~zA) >filelist.txt

以下解决了您遇到的包装问题:

Get-ChildItem -Recurse | select Length,LastWriteTime,FullName | Format-Table -Wrap -AutoSize | out-string -width 4096 | clip

看看这个Reference.

转到文件夹 shift+Right Click ---> Powershell 然后输入此代码。

gci -rec -file|%{"$($_.Length)~$($_.Name)~$($_.FullName)"} >filelist.txt

Ctrl+A 然后 Ctrl+C ---> 复制到 Excel

forfiles /s /c "cmd /c echo @path @fsize" >filelist.txt

OP 使用 PowerShell 选择的答案(以及他们使用 Get-ChildItem -Recurse | select Length,LastWriteTime,FullName | Format-Table -Wrap -AutoSize | Out-File filelist.txt 的评论)几乎是我想要在 Excel 中处理的内容。感谢那部分。

不幸的是,(正如他们所提到的)输出包含长文件路径的换行,这不是我想要的。

以下命令将生成 CSV 格式的文件(无换行):

Get-ChildItem -Recurse | select Length,LastWriteTime,FullName | Export-Csv -path filelist.csv -NoTypeInformation

感谢 关于 Export-Csv

的提示