公司文件共享服务器内的D:\00Product下,一些目录会经常需要修改目录名。目前的方式为让他们自助填写renameproject.txt的内容,然后脚本定期执行。
目前脚本如下,缺点是目标目录(!newfn!)已经存在时,也会把该目录已经打开的文件session关闭。所以想把第七句 for /f ……移到第八句,当!newfn!不存在时,才执行for /f "delims=," %%a in ('openfiles /query /fo csv ^| findstr !oldfn!') do net file %%a /close
试着整合了一下7、8两条语句但是不成功。望指点,谢谢!- @echo off
- setlocal EnableDelayedExpansion
- cd /d D:\00Product
- for /f "tokens=1,2 skip=2" %%i in (RenameProject.txt) do (
- set oldfn=%%i
- set newfn=%%j
- for /f "delims=," %%a in ('openfiles /query /fo csv ^| findstr !oldfn!') do net file %%a /close
- if not exist !newfn! rename !oldfn! !newfn!)
- )
复制代码 Renameproject内容如下
type D:\00Product\RenameProject.txt
###每行一个目录旧名称和新名称,按TAB分隔,本行和下一行不要删###
OldName NewName
CAF01695M00A CAF01695M00B |