Det er ikke et job for bat, men nok nærmere et job for et program (exe) eller et script (vbs).
Følgende burde kunne få dig i gang:
' Monitors a designated folder
Option explicit
Dim strComputer, objWMIService
Dim strFolderName1, strFolderName2
Dim objLatestEvent, colMonitoredEvents, intMonitorInterval
Dim arrNewFile, strFullName
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objShell : Set objShell = CreateObject("Shell.Application")
Dim objFile, objFolder, objFolderItem
'= = = = = = = = = = = = = =
'= = = = = = = = = = = = = =
'> > > > SET FOLDER NAME HERE < < < <
strFolderName1 = "C:\test"
'> > > > SET MONITOR INTERVAL HERE (in seconds) < < < <
intMonitorInterval = 5
'= = = = = = = = = = = = = =
'= = = = = = = = = = = = = =
wscript.echo "Starting to monitor " & chr(34) & strFolderName1 & chr(34) & " now"
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
' specifying directory name for query below is weird: you need four backslashes
' for each backslash and the filename must be surrounded by quotes
strFolderName2 = chr(34) & Replace(strFolderName1, "\", "\\\\") & chr(34)
' statement below creates event that monitors a folder for new files every 5 seconds;
' change "WITHIN 5" to another value to change the time interval
' ("SELECT * FROM __InstanceCreationEvent WITHIN 5 WHERE " _
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
("SELECT * FROM __InstanceCreationEvent WITHIN " & intMonitorInterval & " WHERE " _
& "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _
& "TargetInstance.GroupComponent= " _
& "'Win32_Directory.Name=" & strFolderName2 & "'")
Do
Set objLatestEvent = colMonitoredEvents.NextEvent
arrNewFile = Split(objLatestEvent.TargetInstance.PartComponent, "=")
strFullName = arrNewFile(1)
strFullName = Replace(strFullName, "\\", "\")
strFullName = Replace(strFullName, Chr(34), "")
Set objFolder = objShell.Namespace(strFolderName1)
Set objFolderItem = objFolder.ParseName(GetFileName(strFullName))
wscript.sleep 20000
Set objLatestEvent = Nothing
Set objFile = Nothing
Loop
'= = = = = = = = = = = = = =
Function GetFileName(strFull)
' returns the portion of the passed string that is after the final
' backslash, e.g., just the file name from a full path name
Dim intSlashPos
intSlashPos = Instr(strFull,"\")
if intSlashPos = 0 then
GetFileName = strFull
else
GetFileName = GetFileName(Right(strFull, Len(strFull) - intSlashPos))
end if
End Function
Taget fra
http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Server/2003_Server/Q_24308747.html[Se nederst på siden, så behøves du ikke lave et signup]