2013-08-26 4 views
0

안녕하세요 저는 특정 파일 크기 사이에 마지막 날에 저장된 파일 목록과 함께 일부 디렉토리를 검색하고 텍스트 파일 보고서를 출력하는 배치 파일을 작성하려고합니다.지난 24 시간 동안 저장된 파일 목록을 일괄 처리 파일

파일 크기 부분에는 아무런 문제가 없습니다. 그러나 어떻게 날짜를 구문 분석하고 오늘의 날짜를 확인하고 'if'문에 추가합니까?

이것은 내가 지금까지 무엇을 가지고 :

@echo Report will open when complete 
@echo Working 
@echo off 
setlocal 
set "SEARCH_DIR=f:" 
set "MIN_SIZE=1" 
set "MAX_SIZE=300000" 
set "REPORT=F:\Error_report.txt" 

echo **************************************************** >> %REPORT% 
echo File report %date% %time% >> %REPORT% 
echo File size %MIN_SIZE% to %MAX_SIZE% >> %REPORT% 
echo **************************************************** >> %REPORT% 

echo File list: >> %REPORT% 

for /R "%SEARCH_DIR%" %%F in (*) do (
    if exist "%%F" if %%~zF LSS %MAX_SIZE% if %%~zF GEQ %MIN_SIZE% echo %%F >> %REPORT% 
) 

@echo Done 

START %REPORT% 

나는 if 문에 if forfiles /d +1를 추가 해봤 -하지만이 작동하지 않습니다!

도움을 주시면 감사하겠습니다.

답변

0

find 유틸리티를 직접 사용하지 않는 이유는 무엇입니까? 하나의 호출로 파일 필터링을 수행하고 일부 텍스트에서이를 감쌀 수 있습니다. 예 :

find Documents/ -daystart -mtime "1" -size +1k 

은 자세한 내용은 매뉴얼 페이지를 참조하십시오, 또한 거기에 인터넷에서 예 수백만이있다. 이에 대한 GNU find for Windows을 사용할 수 있습니다

+0

나는 OP가 (li) (n) nix 상자에 없다고 생각합니다. ... – rene

+0

죄송합니다, 실제로 저는 이제 이것을 실제로 MS-Windoze (F : \\'표기법을 발견했습니다)처럼 보입니다. 그렇다면 사실 그런 유틸리티는 사용할 수 없습니다. 죄송합니다. 심지어 나에게 발생하지 않았다, 재미는 여기에 거의 모든 사람들이 SO 요즘 ... – arkascha

+0

이 LOL ... – rene

1

:

find * -size +1k -mtime -1 
내가 PowerShell을 여기에 훨씬 더 적합해야한다고 생각
 
-size n[c] 
    The primary shall evaluate as true if the file size in bytes, divided by 512 and rounded up to the next integer, is n. If n is followed by the character 'c', the size shall be in bytes. 
-atime n 
    The primary shall evaluate as true if the file access time subtracted from the initialization time, divided by 86400 (with any remainder discarded), is n. 
-ctime n 
    The primary shall evaluate as true if the time of last change of file status information subtracted from the initialization time, divided by 86400 (with any remainder discarded), is n. 
-mtime n 
    The primary shall evaluate as true if the file modification time subtracted from the initialization time, divided by 86400 (with any remainder discarded), is n. 

OPERANDS 

    The following operands shall be supported: 

    The path operand is a pathname of a starting point in the directory hierarchy. 

    The first argument that starts with a '-', or is a '!' or a '(', and all subsequent arguments shall be interpreted as an expression made up of the following primaries and operators. In the descriptions, wherever n is used as a primary argument, it shall be interpreted as a decimal integer optionally preceded by a plus ('+') or minus ('-') sign, as follows: 

    +n 
     More than n. 
    n 
     Exactly n. 
    -n 
     Less than n. 


1

:

function Get-ErrorReport { 
    param(
    [string]$Path = 'F:\', 
    [long]$MinSize = 1, 
    [long]$MaxSize = 300000, 
    [string]$OutputPath = 'F:\Error_report.txt' 
) 

    Get-ChildItem -Recurse $Path | 
    Where-Object { 
     $_.Length -ge $MinSize -and 
     $_.Length -le $MaxSize -and 
     $_.LastWriteTime -gt (Get-Date).AddDays(-1) 
    } | 
    Select-Object -ExpandProperty FullName | 
    Out-File $OutputPath 

    Invoke-Item $OutputPath 
} 

은 다양한 방법으로 호출 할 수

Get-ErrorReport 
Get-ErrorReport -MinSize 1KB -MaxSize 10MB 
Get-ErrorReport -Path X:\ -OutputPath X:\report.txt 
... 
관련 문제