2017-12-22 21 views
0

내 폴더가 "C : \ sample \"이라고 가정 해 봅시다. .dat 파일에는 두 가지 유형이 있습니다..dat 파일에서 단어 찾기 및 복사

하나는

Head #Index Name= "DbResultDataHeadStruct" TypeNo VarType = REG_DWORD 0x8 Data = "" TypeA VarType = REG_DWORD 0x8 Data = ""

다른 하나입니다 :

Head #Index Name= "DbResultDataHeadStruct" TypeNo VarType = REG_DWORD 0x8 Data = "" TypeB VarType = REG_DWORD 0x8 Data = ""

만 차이를 보듯이

는 TYPEA와 b를 입력합니다. .dat 파일에 TypeA가 "C : \ sample \ TypeA"이고 TypeB가 "C : \ sample \ TypeB"인 경우 파일 복사/잘라 내기를 원합니다. 이 배치 파일은 항상 새 파일을 기다립니다. 아래에서이 코드를 발견했지만 나에 따라 해결할 수 없습니다. 어쩌면 도움이 될지도 몰라.

@echo off 
setlocal EnableExtensions DisableDelayedExpansion 

rem // Define constants here: 
set "PATTERN=*.dat" 
set "SOURCE=C:\sample\" 
set "TARGET=C:\sample\TypeA" 
set "STRING1=TypeA" 
set "STRING2=TypeB" 

pushd "%SOURCE%" && (
for /F "delims=" %%F in ('findstr /S /M /I /R /C:"\<%STRING1%\>" "%PATTERN%"') do (
    for /F "delims=" %%E in ('findstr /M /I /R /C:"\<%STRING2%\>" "%%F"') do (
     ECHO copy "%%E" "%TARGET%\%%~nxE" 
    ) 
) 
popd 
) 

endlocal 
exit /B 

답변

0

findstr 및 move 명령을 사용하여 해결책을 찾았습니다.

너무 제한 시간을 추가했습니다. 10 초마다 폴더를 확인하고 있습니다.

@echo OFF 
setlocal enableextensions disabledelayedexpansion 

set "source=C:\sample\*.dat" 
set "target=C:\sample\TypeA\OpMode" 
set "target2=C:\sample\TypeB\Error" 
set "searchString=OpMode" 
set "searchString2=Error" 

:loop 
set "found=" 
for /f "delims=" %%a in (' 
    findstr /m /i /l /c:"%searchString%" "%source%" 2^>nul 
') do (
    if not defined found set "found=1" 
    move "%%a" "%target%" 
) 



set "found=" 
for /f "delims=" %%a in (' 
    findstr /m /i /l /c:"%searchString2%" "%source%" 2^>nul 
') do (
    if not defined found set "found=1" 
    move "%%a" "%target2%" 
) 

timeout /T 10 

goto loop