加快批量代码

时间:2015-08-12 11:55:26

标签: batch-file

请问您能为加快我的批次做些什么吗? 分开工作需要很长时间才能完成:)

对于此文字感到抱歉,但由于邮件消息,我无法发布问题'看起来您的帖子主要是代码bla bla bla。管理员 - 您可以关闭此验证!!!

 @echo off
c:
cd \
pushd \\ftp\ftp$

cls
echo ________________________________________________________________
echo.

color f9
:WPIS
set /p moje=Please enter required LOGIN NAME: 
if exist "\\ftp\ftp\Transfer\%moje%" echo USER ALREADY EXIST TRY ANOTHER ONE && GOTO WPIS

:KOD
set mojep=%random%%random%%random%

setlocal enabledelayedexpansion

set input=default2015.Archive
set output2=%moje%.Archive2
set output1=%moje%.Archive1
set output=%moje%.Archive
set text2searchfor=default2015

set password2searchfor=szukajpassword

set folder2search=F:\\Transfer\\default2015
set newfolder=F:\\Transfer\\%moje%

del %output1%
cls
echo Wait....
for /F "tokens=*" %%f in ('type %input%') do (
set line=%%f
if "!line!"=="%text2searchfor%" (
set NAME=%moje%
echo !NAME!>> %output2%
) else (
echo !line!>> %output2%
)
)


for /F "tokens=*" %%f in ('type %output2%') do (
set line=%%f
if "!line!"=="%folder2search%" (
set NAME=%newfolder%
echo !NAME!>> %output1%
) else (
echo !line!>> %output1%
)
)

for /F "tokens=*" %%f in ('type %output1%') do (
set line=%%f
if "!line!"=="%password2searchfor%" (
set NAME=%mojep%
echo !NAME!>> %output%
) else (
echo !line!>> %output%
)
)

del %output1%
del %output2%

pushd \\ftp\ftp\Transfer\
md %moje%
popd \\ftp\ftp\Transfer\
popd \\ftp\ftp$

...

2 个答案:

答案 0 :(得分:2)

试试这个:

@echo off
c:
cd \
pushd \\ftp\ftp$

cls
echo ________________________________________________________________
echo.

color f9
:WPIS
set /p moje=Please enter required LOGIN NAME: 
if exist "\\ftp\ftp\Transfer\%moje%" echo USER ALREADY EXIST TRY ANOTHER ONE && GOTO WPIS

:KOD
set mojep=%random%%random%%random%

setlocal

set input=default2015.Archive
set output2=%moje%.Archive2
set output1=%moje%.Archive1
set output=%moje%.Archive
set text2searchfor=default2015

set password2searchfor=szukajpassword

set folder2search=F:\\Transfer\\default2015
set newfolder=F:\\Transfer\\%moje%

cls
echo Wait....
(for /F "delims=" %%f in (%input%) do (
   if "%%f"=="%text2searchfor%" (
      echo %moje%
   ) else (
      echo %%f
   )
)) > %output2%


(for /F "delims=" %%f in (%output2%) do (
   if "%%f"=="%folder2search%" (
      echo %newfolder%
   ) else (
      echo %%f
   )
)) > %output1%

(for /F "delims=" %%f in (%output1%) do (
   if "%%f"=="%password2searchfor%" (
      echo %mojep%
   ) else (
      echo %%f
   )
)) > %output%

del %output1%
del %output2%

pushd \\ftp\ftp\Transfer\
md %moje%
popd \\ftp\ftp\Transfer\
popd \\ftp\ftp$

如果需要更高的速度,可以通过Batch-JScript混合脚本编写更快的解决方案。

答案 1 :(得分:1)

这使用名为Jrepl.bat(dbenham)的本机Windows批处理脚本 - 从以下网址下载:https://www.dropbox.com/s/4otci4d4s8x5ni4/Jrepl.bat
它也可以在这里找到:http://www.dostips.com/forum/viewtopic.php?f=3&t=6044

对于大型文件而言,它比普通的vanilla for循环要快得多。

这假设你要替换的字符串没有嵌入到任何其他行中,而只是自己发生。

当您更改目录时,将jrepl.bat放在系统路径上是明智的,因此脚本可以找到它,或者硬编码jrepl.bat的路径

@echo off
cd /d c:\
pushd \\ftp\ftp$

cls
echo ________________________________________________________________
echo.

color f9
:WPIS
set /p moje=Please enter required LOGIN NAME:
if exist "\\ftp\ftp\Transfer\%moje%" echo USER ALREADY EXIST TRY ANOTHER ONE && GOTO WPIS

:KOD
set mojep=%random%%random%%random%

setlocal enabledelayedexpansion

set input=default2015.Archive
set output2=%moje%.Archive2
set output1=%moje%.Archive1
set output=%moje%.Archive
set text2searchfor=default2015

set password2searchfor=szukajpassword

set folder2search=F:\\Transfer\\default2015
set newfolder=F:\\Transfer\\%moje%


cls
echo Wait....

call jrepl "%text2searchfor%"      "%moje%"      /L /f %input%  /o %output%
call jrepl "%folder2search%"       "%newfolder%" /L /f %output% /o -
call jrepl "%password2searchfor%"  "%mojep%"     /L /f %output% /o -


pushd \\ftp\ftp\Transfer\
md %moje%
popd \\ftp\ftp\Transfer\
popd \\ftp\ftp$