batch:将文件夹路径存储在变量中

时间:2015-05-03 08:06:44

标签: variables batch-file

Win7的位/ 64位/批次/初学者

总结一下,我正试图

  • 搜索/所有外部驱动器以查找特定文件夹和
  • 将其复制到其他位置。

我查找了for循环和xcopy的东西,但我对批处理脚本完全不熟悉所以这就是我到目前为止所做的:

@echo off

::I found this to be useful for variables in for-loops
Setlocal EnableDelayedExpansion

set odrive=%odrive:~0,2%
set backupcmd=xcopy /S /C /G /D /E /I /R /Y


::this part is meant to find all available drives
for %%i in (D E F G H I J) do if exist %%i: (

::and store the drive name
set target=!target!%%i:\
echo "!target!"
::now I want to find a certain folder and use its filepath
for /d /r "!target!" %%a in (*) do if /i "%%~nxa"=="foldername"

set folderpath=!folderpath!%%a ::I want to use this just like I did earlier
echo "!folderpath!"            ::but it turns out to be empty

::the last step is to use the folderpath for the backupcmd
%backupcmd% "!folderpath!" "%drive%\backedUpFiles"
::reset variables
set "target="
set "folderpath="
)

不知道这是否真的是“好”的批处理脚本,但到目前为止我可以遵循并理解它。我期待错误介于两行之间(字面意思),也许它与我如何使用变量有关。 该错误与“无效的驱动器名称”有关。

我希望有人可以帮助我,因为我已经在几天后完成了搜索代码。

0 个答案:

没有答案