批处理文件移动并将文件夹重命名为相对路径

时间:2013-10-21 14:42:15

标签: windows batch-file

我在Windows 7中有以下批处理文件由上下文菜单快捷方式执行。我的目标是将包含子文件夹和文件的报价文件夹移动并重命名为不同的路径,并在提示时插入项目编号重命名。

for %%Q in (.) do set quotenumber=%%~nQ
for %%Y in (.\..) do set year=%%~nY
for %%C in (.\..\..\..) do set client=%%~nC
set /P projectnumber="Enter Project number>"
move "c:\myfiles\mainfiles\clients\%client%\quotes\%year%\%quotenumber%" "c:\myfiles\mainfiles\clients\%client%\projects\%year%\%projectnumber%"

我收到错误“该进程无法访问该文件,因为它正被另一个进程使用”。 谁能告诉我我做错了什么?我不是程序员,不能让它工作! 任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:3)

查看你的代码我假设你;在c:\myfiles\mainfiles\clients\%client%\quotes\%year%\%quotenumber% dir中重新执行它。 在最后一行中,你试图将同一个dir移动到另一个地方。这是不可能的,因为dir由脚本本身保存。试试这个:

for %%Q in (.) do set quotenumber=%%~nQ
for %%Y in (.\..) do set year=%%~nY
for %%C in (.\..\..\..) do set client=%%~nC
set /P projectnumber="Enter Project number>"
cd ..
move "c:\myfiles\mainfiles\clients\%client%\quotes\%year%\%quotenumber%" "c:\myfiles\mainfiles\clients\%client%\projects\%year%\%projectnumber%"