2015-01-14 3 views
0

방금 ​​배치 파일로 코드하는 법을 배우기 시작했습니다. 배치 파일에 대한 다음 요구 사항에 대한 도움을 주시면 감사하겠습니다.오늘 수정 날짜가있는 디렉토리 검색

나는 몇 가지 조사를 해본 결과이 링크 (Is there a file in a directory with a modified date of today - Batch File)가 어떻게 든 원하는 것과 유사하다는 것을 알게되었습니다.

Are there files in a directory with a modified date of today 

If yes (may have more than one file with the modified date of today) 
    Copy the files into the folder 
else 
    echo no file found 

else 
NO file for today 

나는 솔루션에서 링크를 시도하지만 그 해결책은 하나의 파일 만 반환합니다. 예를 들어, test_20150114와 testString_20150114의 두 파일이 있습니다. 솔루션은 testString_20150114 파일 만 폴더에 복사합니다. test_20150114 및 testString_20150114 파일을 폴더에 복사하고 싶습니다. 나는 그것을 어떻게 성취 할 수 있는가?

두 개의 루프를 사용하여 시도하지만 어떻게 든 실패합니다. 여기

난 내 같은 매우 유사한 요구 사항을 가진 다른 웹 사이트에서 잡아 코드,

for /f "tokens=2" %%I in ("%date%") do set today=%%I 
for /f "tokens=5" %%H in ('dir /a-d ^| findstr /v /i "%~nx0$" ^| find "test"') do (
for /f "tokens=4*" %%H in ('dir /a-d ^| findstr /v /i "%~nx0$" ^| find "%today%"') do (

rem record success for later 
set found=1 

rem search file %%I for "test" (case-insensitive). 
find /i "string" "%%I">NUL 

rem Was last command successful? 
if %ERRORLEVEL%==0 (
    echo test Files Found for today 
If %%H GTR 0 (
    echo Found %%I file is greater than 0kb 
) 
) else (
    echo test string NOT found 
) 
) 
) 
for /f "tokens=5" %%H in ('dir /a-d ^| findstr /v /i "%~nx0$" ^| find "testString"')do(

for /f "tokens=4*" %%H in ('dir /a-d ^| findstr /v /i "%~nx0$" ^| find "%today%"') do (

rem record success for later 
set found=1 

rem search file %%I for "testString" (case-insensitive). 
find /i "string" "%%I">NUL 

rem Was last command successful? 
if %ERRORLEVEL%==0 (
    echo testString Files Found for today 
If %%H GTR 0 (
    echo Found %%I file is greater than 0kb 

) 
) else (
    echo test string NOT found 
) 
) 
) 

* 편집 : 나는 질문에

forfiles /s /m *.* /d 0 /c "cmd /c 
    if @fsize==0 Echo @file is 0Kb || Copy @file D:\Test 

추가 세레의 도움에서이 솔루션을 얻을 관리 : 오늘의 날짜가있는 파일을 찾을 수있게되면, 파일의 내용을 새 파일에 복사하고 싶습니다. Test.txt 내용은 Result.txt에 복사됩니다.

+0

당신이 실제 작동하지 않는 코드를 포함 할 수 라인 명령에? – NiematojakTomasz

답변

0
forfiles /d 0 

목록 파일이 오늘 수정되었습니다.

Forfiles /d 0 && Echo copy etc || Echo File Not Found 

ForFiles는 발견 된 파일에 대해 자체 명령을 실행하고 자체 메시지 File Not Found를 인쇄하지만.

forfiles /d 0 /p c:\windows /m *.ini /s /c "cmd /c copy ^"@path^" c:\somewhereelse\" 

편집 : 추가 된 cmd를/c를

+0

답에 감사드립니다. 오늘 날짜가있는 파일을 검색하는 것 외에도 파일이 0KB보다 큰지 확인하고 싶습니다. 어떻게 할 수 있습니까? – missypooh

+0

forfiles/d 0/c "cmd/c if @ fsize == 0 if echo hi' – Serenity

+0

0 바이트 파일을 복사하려고하면 파일이 삭제 될 것입니다."복사 "는 무엇입니까? – Serenity

관련 문제