Wes*_*ter 80 windows windows-xp xcopy max-path
我在XP Windows脚本中使用xcopy来递归复制目录.我不断收到"Insufficient Memory"错误,我理解这是因为我试图复制的文件路径太长了.我可以轻松地减少路径长度,但不幸的是我无法确定哪些文件违反了路径长度限制.复制的文件将打印到标准输出(我将其重定向到日志文件),但错误消息将打印到终端,因此我甚至无法计算出哪个目录正在给出错误.
rer*_*run 104
执行a dir /s /b > out.txt然后在260位添加指南
在powershell中 cmd /c dir /s /b |? {$_.length -gt 260}
dea*_*dog 28
我为此创建了Path Length Checker工具,这是一个很好的免费GUI应用程序,可用于查看给定目录中所有文件和目录的路径长度.
我还写了一篇关于获取文件和目录长度的简单PowerShell脚本的博客和博客.它将输出文件的长度和路径,并可选择将其写入控制台.它不限制显示仅超过一定长度的文件(一个简单的修改),但显示它们按长度递减,因此仍然可以非常容易地看到哪些路径超过了您的阈值.这里是:
$pathToScan = "C:\Some Folder" # The path to scan and the the lengths for (sub-directories will be scanned as well).
$outputFilePath = "C:\temp\PathLengths.txt" # This must be a file in a directory that exists and does not require admin rights to write to.
$writeToConsoleAsWell = $true # Writing to the console will be much slower.
# Open a new file stream (nice and fast) and write all the paths and their lengths to it.
$outputFileDirectory = Split-Path $outputFilePath -Parent
if (!(Test-Path $outputFileDirectory)) { New-Item $outputFileDirectory -ItemType Directory }
$stream = New-Object System.IO.StreamWriter($outputFilePath, $false)
Get-ChildItem -Path $pathToScan -Recurse -Force | Select-Object -Property FullName, @{Name="FullNameLength";Expression={($_.FullName.Length)}} | Sort-Object -Property FullNameLength -Descending | ForEach-Object {
$filePath = $_.FullName
$length = $_.FullNameLength
$string = "$length : $filePath"
# Write to the Console.
if ($writeToConsoleAsWell) { Write-Host $string }
#Write to the file.
$stream.WriteLine($string)
}
$stream.Close()
Run Code Online (Sandbox Code Playgroud)
Chu*_*lin 24
作为最简单的解决方案的改进,如果您不能或不想安装Powershell,只需运行:
dir /s /b | sort /r /+261 > out.txt
Run Code Online (Sandbox Code Playgroud)
或(更快):
dir /s /b | sort /r /+261 /o out.txt
Run Code Online (Sandbox Code Playgroud)
超过260的行将成为列表的顶部.请注意,必须将1添加到SORT列参数(/ + n).
我已经替代了此处使用 PowerShell 的其他好答案,但我的也将列表保存到文件中。将在这里分享,以防其他人需要类似的东西。
警告:代码覆盖当前工作目录中的“longfilepath.txt”。我知道您不太可能已经拥有一个,但以防万一!
特意将它放在一行中:
Out-File longfilepath.txt ; cmd /c "dir /b /s /a" | ForEach-Object { if ($_.length -gt 250) {$_ | Out-File -append longfilepath.txt}}
Run Code Online (Sandbox Code Playgroud)
详细说明:
cat longfilepath.txt | sort解释:
Out-File longfilepath.txt ;– 创建(或覆盖)一个名为“longfilepath.txt”的空白文件。分号分隔命令。
cmd /c "dir /b /s /a" |– 在 PowerShell 上运行 dir 命令,/a以显示包括隐藏文件在内的所有文件。|管。
ForEach-Object { if ($_.length -gt 250) {$_ | Out-File -append longfilepath.txt}} – 对于每一行(表示为 $_),如果长度大于 250,则将该行附加到文件中。
| 归档时间: |
|
| 查看次数: |
173566 次 |
| 最近记录: |