;------------------------------------------------------------------------------------------------------------------------------------------ ; Wait for file to arrive in folder. ;------------------------------------------------------------------------------------------------------------------------------------------ strFolderWatch = "F:\TEMP\" strFolderWatch = StrSub (strFolderWatch, 1, StrLen (strFolderWatch) - (StrSub (strFolderWatch, StrLen (strFolderWatch), 1) == "\")) ; Remove Backslash. strComputer = "." objWMIService = ObjectGet ("winmgmts:\\" : strComputer : "\root\cimv2") strWQL = `SELECT * FROM __InstanceCreationEvent WITHIN 10 WHERE Targetinstance ISA 'CIM_DirectoryContainsFile' and TargetInstance.GroupComponent='Win32_Directory.Name="{1}"'` strWQL = StrReplace (strWQL, "{1}", StrReplace (strFolderWatch, "\", "\\\\")) colMonitoredEvents = objWMIService.ExecNotificationQuery(strWQL) While @TRUE objLatestEvent = colMonitoredEvents.NextEvent strNewFile = objLatestEvent.TargetInstance.PartComponent strFileName = ItemRemove (1, strNewFile, "=") strFileName = StrReplace (strFileName, "\\", "\") strFileName = StrReplace (strFileName, '"', "") Pause ("CIM_DirectoryContainsFile", "New file arrived:" : @LF : strFileName : @LF : @LF : "Wait for next event?") EndWhile Exit ;------------------------------------------------------------------------------------------------------------------------------------------ ; (c)Detlev Dalitz.20100205.