具有可变目录路径的批处理文件

时间:2014-01-16 15:40:36

标签: batch-file

我有一个简单的移动命令,我需要将其制作成批处理文件。

move" \ company-nas \ local \ Shared \ Sites \ Property_A \ Directory A" " \ company-nas \ local \ Shared \ Sites \ Property_A \ Directory B"

我的问题是Property_A是变量。所以下一个副本是Property_B。等等等等。如何将其转换为批处理脚本?

编辑:

前2 ...

move "\\company-nas\local\Shared\Sites\Arpmanor\Directory A" "\\company-nas\local\Shared\Sites\Arpmanor\Directory B"

move "\\company-nas\local\Shared\Sites\Bailey Lane\Directory A" "\\company-nas\local\Shared\Sites\Bailey Lane\Directory B"

最后2 ....

move "\\company-nas\local\Shared\Sites\Woodstream\Directory A" "\\company-nas\local\Shared\Sites\Woodstream\Directory B"

move "\\company-nas\local\Shared\Sites\Woodview\Directory A" "\\company-nas\local\Shared\Sites\Woodview\Directory B"

1 个答案:

答案 0 :(得分:0)

试试这个:

@echo off
setlocal

for /f "tokens=*" %%a in ('dir /b /ad "\\company-nas\local\Shared\Sites\*"') do (
echo Move "\\company-nas\local\Shared\Sites\%%a\Directory A" ^
   "\\company-nas\local\Shared\Sites\%%a\Directory B"
)

我添加了回声,以便您可以判断输出是否符合您的要求。将其移除以进行实际移动。

(由Magoo修复:需要在dir中包含该目录 - 当然可以使用pushd/popd括号...)