首页 > 解决方案 > Powershell,Excel搜索文件夹

问题描述

我有一个 Excel 列表,其中包含“A”列中的文件夹路径。我想检查这些路径/文件夹是否存在。如果存在,则在“B”列中输入“OK”,如果不存在,则在“B”列中输入“error”。

例子

标签: excelpowershell

解决方案


将 Excel 保存为 CSV 文件

然后在 PowerShell 中执行:

$csv = Import-Csv -Path 'X:\theFile.csv' -Header 'path','exists' -UseCulture
foreach ($item in $csv) {
    $item.exists = if (Test-Path -Path $item.path) {'OK'} else {'error'}
}
# re-save the file
$csv | Export-Csv -Path 'X:\theFile.csv' -UseCulture -NoTypeInformation

最后双击该文件以在 Excel 中打开


推荐阅读