PowerShell 移动/重命名文件:Move-Item(含 -Force)
PowerShell 版的 mv,可移动或重命名文件和文件夹,加 -Force 可覆盖目标同名文件。
使用 Move-Item -Path <源> -Destination <目标>,目标存在同名文件时加 -Force 覆盖。
01命令
命令
$ Move-Item -Path 'C:\Temp\report.csv' -Destination 'D:\Reports\report.csv' -Force02作用说明
Move-Item 同时承担移动和重命名——重命名就是在同一目录内移动。默认遇到同名目标文件会报错“文件已存在”,脚本常见卡点,加 -Force 即可绕过。同一分区内移动只是改元数据,瞬间完成;跨分区则是复制后删除。
03风险
!注意: -Force 会直接覆盖目标文件,执行前可加 -WhatIf 预览影响范围。
04撤销
撤销
$ Move-Item -Path 'D:\Reports\report.csv' -Destination 'C:\Temp\report.csv' -Force05来源
- Move-Item - PowerShell依据: SS64 describes -Force as forcing the command to run without asking for user confirmation, overwriting existing destination files.
- Move-Item | Microsoft Learn依据: Microsoft documents Move-Item with -Force to overwrite an existing destination item and -WhatIf to preview the move.
最后验证: 2026-09-17 · 分类: 文件与文件夹