BATCH / CMD:将.txt的每一行打印到变量中 [英] BATCH/CMD: Print each line of a .txt into a variable

查看:500
本文介绍了BATCH / CMD:将.txt的每一行打印到变量中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目标:将计算机中的每个dll文件传递到regsvr32.exe

Goal: Have every dll file in a computer passed into regsvr32.exe

完成:
cd\

:: REM将每个文件和目录(/ s)导出到c:的根目录中的文件(仅包含文件名(/ b)的dir.txt)

dir / s /b>>dir.txt

:: REM现在,这将包含每个扩展类型。我们只需要dll,所以我们找到dll.txt:

findstr.dll $dir.txt >> dll.txt

Accomplished: cd\
::REM Exports every file and directory (/s) into a file in root of c: called dir.txt with only file names (/b)
dir /s /b>>dir.txt
::REM Now, this will contain every extension type. We only want dll's, so we findstr it into dll.txt:
findstr ".dll$" dir.txt>>dll.txt

扭结:

现在,如果我想regsvr32.exe文件每个文件,现在在dll.txt,我不知何故需要得出每个单独的文件名是单独在每行上。我想知道是否有第三方命令行工具,可以导出文件的每一行到一个变量。这样,我可以:

Now, if I want to regsvr32.exe "file" every file that is now in dll.txt, I somehow need to get out every individual filename that is individually on each line. I was wondering if there is a third party command line tool that can export each line of the file into a variable. This way, I could:

==========

==========

这个工具有行号的开关/ l,和使用变量的/ v:,结尾使用file:

::REM assume this tool had switches /l for the line number, and /v:"" for variable to use, and used "file" at the end:

set line=1  
:loop  
set dll=  
tool.exe /l %line% /v:"dll" "dll.txt"  
::REM We if defined here because if the line doesn't exist in dll.txt, the tool would return nothing to %dll%
if not defined %dll% exit  
::REM With the variable defined, we can continue  
regsvr32.exe %dll%  
set /a line=%line%+1  
goto loop  

=====================

=======================

然后工具将处理文件的每一行的每个路径,直到它自动退出,因为将没有更多的行。循环后的注意事项我将dll设置为无,这样'如果未定义'将每次都会工作。

Then the tool would process each path of each line of the file until it exits automatically, because there would be no more lines. Notice right after loop I set dll to nothing so that 'if not defined' will work each time.

如果这种类型的第三方工具无法完成,一个方法做到这一点?

If this type of third-party tool cannot be done, is there a way to do that with for?? I honestly never learned for, and tried to but could never figure it out.

任何帮助都非常感谢!

如果这已经回答了,很抱歉。

Sorry if this has already been answered.

EDIT / UPDATE:
我发现了如何使这项工作。

EDIT/UPDATE: I have discovered how I will make this work.

感谢: http://pyrocam.com/re-register-all-dlls-to-fix-no-such-interface-支持的错误在Windows-7-after-installing-ie7-standalone /

和:在批处理文件中逐行读取txt

第一个链接显示手动替换开头的regsvr32.exe

第二个显示如何使用在这种情况下{也感谢craig65535为他的帮助:}}

The first link shows manually replacing the beginning with regsvr32.exe
The second shows how to use for in this case {also thanks to craig65535 FOR his help :)}

代码:

Code:

@echo off
color 1f
title Register .dll
echo.
echo Exporting file list . . .
echo.
cd /d c:
cd\
if exist dll.txt del dll.txt
if exist dir.txt del dir.txt
if exist dll.bat del dll.bat
echo Part 1 of 3 . . .
echo.
dir /s /b>>dir.txt
echo Part 2 of 3 . . .
echo.
findstr ".dll$" dir.txt>>dll.txt
del dir.txt
echo Part 3 of 3 . . .
echo.
for /f "delims=" %%i IN ('type dll.txt') do echo regsvr32.exe /s "%%i">>dll.bat
del dll.txt
echo Ready to begin regsvr32.exe . . .
echo.
pause
echo.
echo Beginning registration . . .
echo *This will take time, close any popups that occur
echo.
call dll.bat
echo.
echo Deleting registration file . . .
if exist dll.bat del dll.bat
echo.
echo DONE.
echo.
pause >nul


推荐答案

for /f %%f in ('type dll.txt') do regsvr32.exe %%f

code>键入dll.txt ,并在 %% f 中一次输入一行。然后,您可以使用 %% f 作为其他命令的参数。

That takes the output of type dll.txt and puts one line at a time into %%f. You can then use %%f as an argument for some other command.

regsvr32.exe %% f ,您可以写另一个批处理文件并调用:

If you want to do more than regsvr32.exe %%f, you can write another batch file and call that:

for /f %%f in ('type dll.txt') do call process.bat %%f


b $ b

process.bat会接收到%1 的文件名。

这篇关于BATCH / CMD:将.txt的每一行打印到变量中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆