【发布时间】:2013-01-08 06:48:44
【问题描述】:
今天早上,我从本地网络驱动器复制了一个目录到临时文件夹进行测试。出现了这个错误。
Get-Content : Cannot find path 'C:\users\xxxxx\desktop\cgc\Automatic_Post-Call_Survey_-_BC,_CC.txt' because it does no
t exist.
At C:\users\xxxxx\desktop\cgc\testcountexcl1.ps1:55 char:12
+ Get-Content <<<< $txtfile | Get-WordCount -Exclude (Get-Content c:\temp\exclude.txt) | select -First 15
+ CategoryInfo : ObjectNotFound: (C:\users\xxxxx...ey_-_BC,_CC.txt:String) [Get-Content], ItemNotFoundEx
ception
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetContentCommand
这是预期的移动...PS找不到引用的路径...但是我在运行脚本之前进行了以下更改(旧的在新的上方注释掉了):
$input = Get-Content c:\temp\wordCount.txt
<# $inpath = "C:\users\xxxxx\desktop\cgc\tx" #>
$inpath = "C:\temp\tx"
$srcfiles = Get-ChildItem $inpath -filter "*.txt"
$notPermittedWords = Get-Content c:\temp\exclude.txt
我的第一个想法是,有某种缓存保存了我上次运行时的 $inpath 变量……但无法确定这是否是预期的 PowerShell 行为。我是否误解了错误或解决方案?如何刷新缓存或任何可能存储在内存中的变量?
【问题讨论】:
-
您确定整个代码都运行了两次吗?设置
$inpath和$srcfiles的行都以新值第二次执行? -
它们是用新值执行的,但表现得好像它们被传递了旧值。
标签: caching powershell