2012-09-10 2 views
1

매분마다 파일이 추가되는 워크 스테이션에 폴더가 있습니다. 새로운 파일이 추가되는지 확인하기 위해이 폴더를 모니터링해야합니다. 5 분 동안이 폴더에 새 파일이없는 경우 작업을 수행합니다.배치 파일을 사용하여 폴더의 최종 수정 시간을 모니터링하십시오.

지난 5 분 동안 새 파일이 추가되지 않으면 창 화면에 경고/팝업이 표시되는 방식으로 배치 파일을 사용할 수 있습니까? 또한 일괄 처리를 처음 사용했습니다. 단계를 알려주십시오.

답변

0

순전히 배치 파일로 수행하고자하는 일은 거의 없을 것 같습니다.

그러나 비교적 간단한/작은 VB 스크립트에서이 작업을 수행 할 수 있습니다.이 스크립트는 시스템에 추가로 설치할 필요가 없습니다.

'------------------------------------------------------------- 
' Monitors a folder for new files and warns if they 
' are not being created within a certain time period. 
'------------------------------------------------------------- 
Dim intMinutes:  intMinutes = 5   ' minute threshold for warning of no new files 
Dim strDrive:  strDrive = "c:"   ' drive to monitor 
Dim strPath:   strPath = "\\temp\\"  ' path to monitor. remember to double slashes 

Dim intTimer:  intTimer = "2" 
Dim strComputer:  strComputer = "." 
Dim objWMIService: Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
Dim strQuery:  strQuery = "Select * From __InstanceOperationEvent" & " Within " & intTimer & " Where Targetinstance Isa 'CIM_DataFile'" & " And TargetInstance.Drive='" & strDrive & "'" & " And TargetInstance.Path='" & strPath & "'" 
Dim colEvents:  Set colEvents = objWMIService. ExecNotificationQuery (strQuery) 
Dim LastNew:   LastNew = Now 
WScript.Echo "Monitoring new file creation... Press [Ctrl]-[C] to exit" 
Do 
    Set objEvent = colEvents.NextEvent() 
    Set objTargetInst = objEvent.TargetInstance 
    Select Case objEvent.Path_.Class 
     Case "__InstanceCreationEvent" 
      LastNew = Now 
    End Select 
    if DateDiff("n",LastNew,Now) >= intMinutes then 
     ' put whatever actions you want in here... the following two lines are for demo purposes only 
     msgbox "The last new file was " & DateDiff("n",LastNew,Now) & " minute ago!",0,"No New Files" 
     exit do 
    end if 
Loop 

는 CScript를 볼 또는 하지 콘솔 창을 표시 할 수 있도록 에 WScript와는 이것을 실행합니다.

IF 블록 내부의 코드를 바꿔 필요한 작업을 수행하십시오 (문제를 알려주십시오).