2016-03-29 18 views
1

Bunun neden işe yaramayacağına dair bir fikriniz var mı? Belirli bir dize (123456) için geçerli dizinde tüm toplu iş dosyalarını taramak için bir dosya oluşturmaya çalışıyorum. Bulunmazsa, dosya kendini taranan dosyaya kopyalamalı ve sonraki dosyayı taramaya devam etmelidir. Herhangi bir fikir ve ipuçları takdir edilmektedir! Şerefe! Toplu iş için döngü/çoklu komutlar

for %%f in (*.bat) do (
     set A=%%f 
     set file=%A% 
     findstr "123456" %file% 
     if %errorlevel%==0 goto end 
     copy %0 %A% 
     ) 
    :end 

Aşağıdaki kodu test:

SETLOCAL EnableExtensions EnableDelayedExpansion 
    for %%f in (*.bat) do (
     set A=%%~f 
     set file=%A% 
     findstr "123456" %file% 
     if %errorlevel%==0 goto end 
     copy %0 %A% 
     ) 
    :end 

ve kod git uç komutunu çalıştırmak yoktu. Çıktı aşağıdaki gibidir:

C:\Users\Epidex98\Desktop\routine>(
    set A=ir.bat 
    set file= 
     findstr "123456" 
    if 0 == 0 goto end 
    copy "C:\Users\Epidex98\Desktop\routine\ir.bat" 
    ) 
+1

tutan bir klasörde bu test etmeyi unutmayın İhtiyacınız olan diğer komutların tek kopyaları. – LinuxDisciple

cevap

3
SETLOCAL EnableExtensions EnableDelayedExpansion 
for %%f in (*.bat) do (
    set A=%%~f 
    set file=!A! 
    findstr "123456" !file! 
    if !errorlevel!==0 goto :end 
    copy %0 !A! 
    ) 
:end 

veya daha basit

SETLOCAL EnableExtensions EnableDelayedExpansion 
for %%f in (*.bat) do (
    findstr "123456" "%%~f" 
    if !errorlevel!==0 goto :end 
    copy %0 "%%~f" 
    ) 
:end 

Ancak, nedense gecikmeli genişleme uygulayamaz eğer:

SETLOCAL EnableExtensions DisableDelayedExpansion 
for %%f in (*.bat) do (
    set A=%%f 
    call :proc 
    if errorlevel 0 goto :end 
    copy %0 %%f 
    ) 
rem next command skips :proc subroutine 
goto :end 

:proc 
    set file=%A% 
    findstr "123456" %file% 
    set /A myerror=%errorlevel%-1 
exit /B %myerror% 

:end 

Kaynaklar (gereken okuma):

İlgili konular