windows – 使用New-Item创建目录的竞争条件?

我在调用New-Item以使用UNC路径在外部计算机上创建目录时看到了竞争条件.代码如下:
New-Item $target -itemType Directory -Force -Verbose |
        %{ Write-Host "Creating dir" $_.FullName }

之后立即使用Test-Path返回false.我把测试路径 – >睡眠1秒重试循环,睡眠1秒后,Test-Path返回true.

New-Item是阻止通话吗?我应该在打电话给New-Item后等待吗?

我无法重现你的问题.
PS > New-Item "test" -itemType Directory -Force -Verbose | %{ Test-Path $_.FullName }
VERBOSE: Performing the operation "Create Directory" on target "Destination: C:\Users\Frode\Desktop\test".
True

New-Item通过获取父目录的DirectoryInfo对象并将其调用为CreateSubDirectory来创建新目录,如:

DirectoryInfo subdirectory = new DirectoryInfo(parentPath).CreateSubdirectory(childName);

我不是开发人员,但AFAIK意味着它是一个阻塞调用,因为它等待一个DirectoryInfo对象作为回报.所以mabe的问题在于您的存储子系统.

相关文章

文章浏览阅读2.2k次,点赞6次,收藏20次。在我们平时办公工作...
文章浏览阅读1k次。解决 Windows make command not found 和...
文章浏览阅读3.2k次,点赞2次,收藏6次。2、鼠标依次点击“计...
文章浏览阅读1.3w次。蓝光版属于高清版的一种。BD英文全名是...
文章浏览阅读974次,点赞7次,收藏8次。提供了更强大的功能,...
文章浏览阅读1.4w次,点赞5次,收藏22次。如果使用iterator的...