我正在尝试使用Powershell脚本完成以下任务:
%AppData%
目录中的所有json文件。 .json found in
我是PowerShell的新手,到目前为止有以下内容,
$AppData = Get-ChildItem $env:SystemDrive\Users | where {$_.PsIsContainer} | Foreach-Object {$_.FullName}
$Result=Get-ChildItem -Filter *.json -recurse
ForEach ($result in $appdata) { IF($Result -like '*.json') {$result }}
我需要弄清楚如何将appdata的文件夹名称附加到
$AppData
变量输出中。是否有比使用ForEach循环更好的方法?
最佳答案
您可以使用ForEach-Object
cmdlet枚举元素,然后使用Write-Host
cmdlet在控制台中显示结果。像这样:
Get-ChildItem C:\TMP -Filter '*.json' -File -Recurse | ForEach-Object {
Write-Host $('{0} found in {1}' -f $_.Name, ([System.IO.Path]::GetDirectoryName($_.FullName)))
}
关于powershell - 使用powershell查找位于每个用户的%AppData%目录中的特定文件类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52662226/