标题: [文件操作] BAT批量重命名SMB共享目录的疑问 [打印本页]
作者: n度自由 时间: 2020-5-20 14:28 标题: BAT批量重命名SMB共享目录的疑问
公司文件共享服务器内的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
作者: edison_zhu 时间: 2020-5-20 15:02
会用FOR的太牛B了,
无法帮你,水平不行
作者: Batcher 时间: 2020-5-20 15:20
回复 1# n度自由 - @echo off
- setlocal EnableDelayedExpansion
- cd /d "D:\00Product"
- for /f "tokens=1,2 skip=2" %%i in ('type "RenameProject.txt"') do (
- set "oldfn=%%i"
- set "newfn=%%j"
- if not exist "!newfn!" (
- for /f "delims=," %%a in ('openfiles /query /fo csv ^| findstr "!oldfn!"') do (
- net file %%a /close
- )
- ren "!oldfn!" "!newfn!"
- )
- )
复制代码
作者: n度自由 时间: 2020-5-20 15:30
@echo off
setlocal EnableDelayedExpansion
cd /d "D:\00Product"
for /f "tokens=1,2 skip=2" %%i in ('type "RenameProject.txt"") do (
set "oldfn=%%i"
set "newfn=%%j"
if not exist "!newfn!" (
for /f "delims=," %%a in ('openfiles /query /fo csv ^| findstr "!oldfn!"') do (
net file %%a /close
)
ren "!oldfn!" "!newfn!"
)
)
多谢版主,红色标记部分是否应为' ?
作者: Batcher 时间: 2020-5-20 16:09
回复 4# n度自由
是的
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |