powershell - PowerShell Rename-Item正在创建文件的副本

标签 powershell file-rename windows-server-2016

我的脚本应该将c:\ myfolder \ myfile.txt重命名为myfile.bak

Rename-Item "c:\myfolder\myfile.txt" -NewName "myfile.bak"

但是,它将myfile.txt保留在原处,而是创建一个名为myfile.bak的新文件。

有人知道为什么吗?

最佳答案

如果它是隐藏文件或只读文件,则必须添加-force参数:

Forces the cmdlet to rename items that cannot otherwise be changed, such as hidden or read-only files or read-only aliases or variables. The cmdlet cannot change constant aliases or variables. Implementation varies from provider to provider. For more information, see about_Providers.

关于powershell - PowerShell Rename-Item正在创建文件的副本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49171539/

相关文章:

powershell - 无法通过 PowerShell 使用功能接收器启用功能

powershell - Powershell变量分配与管道

regex - 删除部分文件名

Python 程序重命名文件名,如果已经存在该文件则覆盖

c++ - 为什么 CoCreateInstance 在某些 Windows 上返回 REGDB_E_CLASSNOTREG?

windows - 在所有图像/文件完成之前页面停止加载

linux - 搜索模式并替换同一行中 = 和 ""之后的内容

java.io : Rename all elements of an absolute File path

python - IIS winserver 2016 wfastcgi 处理程序行 791 上的 django

powershell - 'AdditionalDeploymentContributors' 不是 'Publish' 操作的有效参数