问题描述
我试图写一个Windows 7的一个批处理文件,将创建100名的文本文件 - EX1至EX100。在每一个文件,我需要使用相同的文字作为文件名来替换给定文本(如EX3)。
I am trying to write a batch file for Windows 7 that will create 100 text files with names - ex1 to ex100. In each file i need to replace a given text (eg. ex3) with the same text as the name of the file.
到目前为止,我已经设法让该批处理文件来创建100个文件但是文本(EX3)是通过EX1在每个文件所取代。
So far I have managed to get the batch file to create the 100 files however the text (ex3) is replaced by ex1 in each file.
下面是我用code。我是一个完整的新手到这一点,从我发现位拼凑起来的。
Here is the code that I have used. I am a complete novice to this and have cobbled it together from bits that I have found.
@echo off
setlocal enabledelayedexpansion
FOR /F "usebackq delims=" %%G IN ("c:\batch\batch.txt") DO (
Set Line=%%G
Set Line=!Line:"='!
Call:replace "!Line!"
)
pause
goto:eof ------------
:replace subroutine
(Set Line=%*&Set Line=!Line:~1,-1!)
Set Line=!Line:'="!
For /l %%A in (7,1,100) do Set "Line=!Line:ex3=ex%%A!"
For /l %%n in (1,1,100) do echo.!Line! >>"c:\batch\ex%%n.txt"
goto:eof ------------
有什么建议?
推荐答案
哇 - 这code是方式更令人费解的比需要的(也是缓慢的,因为CALL的)
Wow - that code is way more convoluted than is needed (and also slow because of CALL).
@echo off
setlocal enableDelayedExpansion
set "folder=c:\batch"
for /l %%N in (1 1 100) do del "%folder%\ex%%N.txt" 2>nul
for /f "usebackq delims=" %%A in ("%folder%\batch.txt") do (
set "line=%%A"
for /l %%N in (1 1 100) do (echo !line:ex3=ex%%N!)>>"%folder%\ex%%N"
)
这篇关于超过100个批处理文件越来越多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!