Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 在cmd中为循环解除链接_Batch File_For Loop_Command Line_Cmd - Fatal编程技术网

Batch file 在cmd中为循环解除链接

Batch file 在cmd中为循环解除链接,batch-file,for-loop,command-line,cmd,Batch File,For Loop,Command Line,Cmd,基本上,我只想使用一个变量,而不是永久值 我有一个for循环,它可以工作 set OS_ROOT=%systemdrive% for /f "delims= " %%A IN ('DIR E:\BACKUP /A:D /O:-D /TW /B') DO (xcopy/e E:\BACKUP\%%A %OS_ROOT%\TempFestplatte) 但一旦我实现变量: SET STICK_ROOT=%CD:~0,3% 恰好是“E:\”,并在我的循环中使用它: for /f "delims

基本上,我只想使用一个变量,而不是永久值

我有一个for循环,它可以工作

set OS_ROOT=%systemdrive%

for /f "delims= " %%A IN ('DIR E:\BACKUP /A:D /O:-D /TW /B') 
DO (xcopy/e E:\BACKUP\%%A %OS_ROOT%\TempFestplatte)
但一旦我实现变量:

SET STICK_ROOT=%CD:~0,3%
恰好是“E:\”,并在我的循环中使用它:

for /f "delims= " %%A IN ('DIR %STICK_ROOT%\BACKUP /A:D /O:-D /TW /B') 
DO (xcopy/e %STICK_ROOT%\BACKUP\%%A %OS_ROOT%\TempFestplatte)
它不起任何作用,摩尔。而且只在'DIR(…)之后


为什么?

请避免在引用驱动器的根文件夹时使用双反斜杠

:: Set variable in terms of current directory drive
set "STICK_ROOT=%cd:~0,2%"

:: Set variable in terms of current batch file drive
set "STICK_ROOT=%~d0"

不确定这两个选项中哪一个更适合你的情况

您正在执行的
DIR E:\\Backup
将给出“文件名、目录名或卷标语法不正确”。请将
SET STICK\u ROOT=%CD:~0,3%
更改为
SET STICK\u ROOT=%CD:~0,2%