windows 仅在命令行中列出带有路径和文件大小的文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43904684/
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
List files with path and file size only in Command Line
提问by user3026965
Windows Command Line (or maybe PowerShell).
Windows 命令行(或者可能是 PowerShell)。
How can I list all files, recursively, with full path and filesize, but without anything else and export to a .txt file. Much preferably a code that works for whichever current directory I am in with the Command Line (so does not require manual entering of the target directory).
如何递归地列出所有文件,包括完整路径和文件大小,但没有其他任何内容并导出到 .txt 文件。最好是适用于我使用命令行所在的任何当前目录的代码(因此不需要手动输入目标目录)。
None of these provides path\filename and filesize only:
这些都不提供路径\文件名和文件大小:
dir /s > filelist.txt
dir /s/b > filelist.txt
dir /s/o:-d > filelist.txt
Desired output (fullpath\file.ext filesize):
所需的输出(完整路径\file.ext 文件大小):
c:\aaa\file.ext 7755777
c:\aaa\bbb.txt 897667
c:\aaa\bbb.ext 67788990
c:\aaa\bbb\nnn\a.xls 99879000
采纳答案by Daniel Agans
Get-ChildItem -Recurse | select FullName,Length | Format-Table -HideTableHeaders | Out-File filelist.txt
回答by Daniel Agans
PowerShell:
电源外壳:
gci -rec -file|%{"$($_.Fullname) $($_.Length)"} >filelist.txt
earlier PowerShell versions:
较早的 PowerShell 版本:
gci -rec|?{!$_.PSIsContainer}|%{"$($_.Fullname) $($_.Length)"} >filelist.txt
Batch file:
批处理文件:
(@For /F "Delims=" %%A in ('dir /B/S/A-D') Do @Echo %%~fA %%~zA) >filelist.txt
Cmdline
命令行
(@For /F "Delims=" %A in ('dir /B/S/A-D') Do @Echo %~fA %~zA) >filelist.txt
回答by Al Raja
The following removes the wrapping issue you have:
以下内容消除了您遇到的包装问题:
Get-ChildItem -Recurse | select Length,LastWriteTime,FullName | Format-Table -Wrap -AutoSize | out-string -width 4096 | clip
Have a look at this Reference.
看看这个参考。
回答by BobTheBuilder7000
Go to folder and shift+Right Click
---> Powershell and then put in this code.
转到文件夹和shift+Right Click
---> Powershell,然后输入此代码。
gci -rec -file|%{"$($_.Length)~$($_.Name)~$($_.FullName)"} >filelist.txt
gci -rec -file|%{"$($_.Length)~$($_.Name)~$($_.FullName)"} >filelist.txt
Ctrl+A
then Ctrl+C
---> Copy into Excel
Ctrl+A
然后Ctrl+C
---> 复制到 Excel
回答by franzo
forfiles /s /c "cmd /c echo @path @fsize" >filelist.txt