【发布时间】:2014-07-08 10:08:53
【问题描述】:
我正在尝试重命名一个文件,但 powershell 认为我的变量是一个字符串并且失败了。
这是脚本:
$date=(get-date -Format d)
$time=(get-date -Format t)
$source = "D:\_qapi.log"
$newfilename = "$date"+"_"+"$time"+"_qapi[SERVERNAME].log"
Rename-Item $source -NewName $newfilename
这是错误:
Rename-Item : Cannot rename because the target specified represents a path or device name.
有人知道我可以解决这个问题吗?由于某种原因,powershell 将 $newfilename 中的 $date 变量视为路径。
【问题讨论】:
标签: powershell rename rename-item-cmdlet