Epl*_*gam 2 windows powershell batch-file
我正在寻找一个可以从命令行(批处理\ PowerShell)运行的脚本,该脚本将遍历文件夹及其子文件夹,并返回一个数字,该数字是最长文件路径的长度。
我已经看到了一些批处理和 PowerShell 脚本,例如
如何在 Windows 中查找路径长度大于 260 个字符的文件?
但它们都不能满足我的要求。
请注意,文件路径可能超过 256 个字符
电源外壳:
((Get-ChildItem -Recurse).FullName | Measure-Object -Property Length -Maximum).Maximum
Run Code Online (Sandbox Code Playgroud)
命令行:
powershell -exec Bypass -c "((dir -rec).FullName | measure Length -max).Maximum"
Run Code Online (Sandbox Code Playgroud)
与错误Get-ChildItem : The specified path, file name, or both are too long相关::读取最大路径长度限制和相关的[PowerShell] 标记的 StackOverflow 线程。
PS D:\PShell> ((Get-ChildItem "D:\odds and ends" -Directory -Recurse).FullName | Measure-Object -Property Length -Maximum).Maximum
242
PS D:\PShell> ((Get-ChildItem "D:\odds and ends" -Recurse -ErrorAction SilentlyContinue).FullName | Measure-Object -Property Length -Maximum).Maximum
242
Run Code Online (Sandbox Code Playgroud)
请注意,-ErrorAction SilentlyContinue上面的命令仅禁止显示错误消息。但是,我知道后面242返回的值是错误的。
我的解决方法适用cmd /C dir /B /S而不是(Get-ChildItem -Recurse).FullName如下:
PS D:\PShell> $x = (. cmd /C dir /B /S "D:\odds and ends")
PS D:\PShell> $y = ( $x | Measure-Object -Property Length -Maximum).Maximum
PS D:\PShell> $y
273
PS D:\PShell> $z = $x | Where-Object { $_.Length -gt 260 }
PS D:\PShell> $z.GetTypeCode()
String
PS D:\PShell> $z
D:\odds and ends\ZalohaGogen\WDElements\zalohaeva\zaloha_honza\Music\Jazz\!Kompilace\Saint Germain des Pres Cafe Vol. 1 to 8 - The Finest Electro Jazz Complication\Saint Germain Des Pres Cafe Vol. 7 - The Finest Electro Jazz Complication\CD 1\Configuring and Using Inte.txt
PS D:\PShell>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5729 次 |
| 最近记录: |