【问题标题】:Powershell: Create folder with '.' in the namePowershell:使用“。”创建文件夹在名字里
【发布时间】:2022-01-18 14:45:43
【问题描述】:

我正在尝试创建一个包含“.”的文件夹在名称中使用以下命令在 Powershell 中失败:

New-Item -ItemType Directory -Force -Path "MyDocuments.pictures"

它静默失败,不会抛出任何异常或错误。 运行此命令时我也有管理员权限。

【问题讨论】:

  • 我尝试时无法重现;如果添加-ErrorAction Stop,会出现错误吗?
  • 你是怎么断定它不起作用的?对Get-Item "MyDocuments.pictures" 的后续调用会引发错误吗?
  • 你有那个文件夹的写权限吗?
  • 如何提供该文件夹的完整路径?您是否在正确的地方寻找它?

标签: windows powershell command-line


【解决方案1】:

路径不是文件夹本身,而是您要在其中创建文件夹的文件夹。这对我有用:

$DirName = "MyDocuments.pictures"
New-Item -ItemType Directory -Path "C:\temp" -Name $DirName | Out-Null
Get-Item "C:\temp\$DirName"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-04
    • 2018-09-27
    • 1970-01-01
    • 1970-01-01
    • 2014-05-08
    相关资源
    最近更新 更多