映射网络驱动器上PowerShell移动文件报错问题求助
PowerShell脚本整理网络驱动器文件的运行与占用问题求助
我写了个简单的PowerShell脚本,用来把下载目录里的文件自动归类到对应文件夹,但现在碰到两个头疼的问题,想请大家帮忙排查解决:
- 脚本没法从映射的网络驱动器(M:)运行——双击脚本后PowerShell窗口只是短暂弹出,完全没有执行文件移动的操作;
- 在PowerShell ISE里手动运行时,偶尔能移动部分文件,但每一条
Move-Item命令都会报错:
Move-Item : The process cannot access the file because it is being used by another process.
At line:1 char:1
我的脚本代码如下:
cls cd M:\!Pool Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy ByPass Move-Item -Path ".\*Video\*" -Destination ".\\Video" Move-Item -Path ".\*Club\*" -Destination ".\\Club" -Exclude *DanceClub* Move-Item -Path ".\\Express Audio\*" -Destination ".\\Express Audio" Move-Item -Path ".\\Alternative\*" -Destination ".\\Alternative" Move-Item -Path ".\\Country Radio\*" -Destination ".\\Country" Move-Item -Path ".\\Contemporary Christian\*" -Destination ".\\Contemporary Christian" Move-Item -Path ".\*Dance Radio\*" -Destination ".\\Dance Radio" Move-Item -Path ".\*Mainstream Radio\*" -Destination ".\\Mainstream Radio" Move-Item -Path ".\\Modern Rock\*" -Destination ".\\Modern Rock" Move-Item -Path ".\\Rhythm Radio\*" -Destination ".\\Rhythm Radio" Move-Item -Path ".\\Urban\*" -Destination ".\\Urban" Move-Item -Path ".\\Caribbean\*" -Destination ".\\Caribbean" Move-Item -Path ".\*Latin\*" -Destination ".\\Latin" -Exclude *Caribbean*
我的PowerShell版本信息:
Name Value ---- ----- PSVersion 5.1.19041.2364 PSEdition Desktop PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...} BuildVersion 10.0.19041.2364 CLRVersion 4.0.30319.42000 WSManStackVersion 3.0 PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1
我知道这个脚本还有优化空间,而且目前也有批处理文件能完成同样的整理工作,但我还是想解决这个PowerShell脚本的问题,麻烦各位大佬支支招!
内容的提问来源于stack exchange,提问作者Aaron M.
相关产品推荐
相关产品推荐

