Loops 如何在批处理文件编程中使用for循环
我想创建一个自动运行的数据备份。为此,我想在system32中注册所有的ocx和dll。我想使用loop来实现这一点,因为当我们添加新的dll时,我们不需要在批处理文件中为其编写额外的代码。下面的代码工作正常,但我想使用循环Loops 如何在批处理文件编程中使用for循环,loops,batch-file,Loops,Batch File,我想创建一个自动运行的数据备份。为此,我想在system32中注册所有的ocx和dll。我想使用loop来实现这一点,因为当我们添加新的dll时,我们不需要在批处理文件中为其编写额外的代码。下面的代码工作正常,但我想使用循环 Set "tempFile=msdbrptr.dll" Set "tempPath=%rootPath%%tempFile% if not exist %tempPath% @ copy controls\%tempFile% %tempPath% regsvr32 %t
Set "tempFile=msdbrptr.dll"
Set "tempPath=%rootPath%%tempFile%
if not exist %tempPath% @ copy controls\%tempFile% %tempPath%
regsvr32 %tempPath%
Set "tempFile=scrrun.dll"
Set "tempPath=%rootPath%%tempFile%
if not exist %tempPath% @ copy controls\%tempFile% %tempPath%
regsvr32 %tempPath%
我们如何使用for loop进行此操作..测试:
@echo off
for %%a in (
"msdbrptr.dll"
"scrrun.dll"
) do (
if not exist "%rootPath%\%%~a" (
copy "controls\%%~a" "%rootPath%"
regsvr32 "%rootPath%\%%~a"
)
)
pause
对于(%windir%\system32\*.ocx%windir%\system32\*.dll)中的%%A执行(regsvr32%%A®svr32/i%%A)
在上述代码中,我从控制文件夹复制并在system32中注册。。对于(%windir%\system32*.ocx%windir%\system32*.dll)中的%%A,我们在此代码中定义控制文件夹的位置(regsvr32%%A®svr32/i%%A)没有控制目录。控制面板是一个虚拟文件夹,其中没有文件。您还编辑了我的代码,因此通过删除反斜杠它将不再工作。我是说您正在从windir中选择dll和ocx并在sys32中注册。。。我想从外部文件夹复制dll和ocx,并注册到sys32或syswow32中,如果不存在,这一行正在执行%tempPath%@copy controls\%tempFile%%tempPath%regsvr32%tempPath%,其中rootpath是rootpath=%SystemRoot%\System32\“忘记变量,用简单的英语说吧。我不知道您认为变量中有什么(至少有一些是不必要的定义。您建议如何告知要复制到哪个文件夹?