问题
I need a vbscript that monitors a folder for a specific file, when file is found it needs to execute a command then delete that file but continue to monitor the folder again for the same file incase it needs to run again.
This...
Set FSO = CreateObject("Scripting.FileSystemObject")
Do While 1>0
If FSO.FileExists (file.txt) Then
FSO.DeleteFile (file.txt)
CreateObject("WScript.Shell").Run "c:\windows\notepad.exe"
End If
WScript.Sleep 1000
Loop
Gave me an "object required: file"
error.
update, this worked...
FileName = "c:\vbscript\cat.txt"
Set FSO = CreateObject("Scripting.FileSystemObject")
Do
If FSO.FileExists(FileName) Then
FSO.DeleteFile FileName
CreateObject("WScript.Shell").Run "c:\windows\notepad.exe"
End If
WScript.Sleep 1000
Loop
回答1:
Simply create a script that infinitely loops, testing for file existence and if it does delete it.
FileName = "Path\To\FileName"
Set FSO = CreateObject("Scripting.FileSystemObject")
Do
If FSO.FileExists(FileName) Then
FSO.DeleteFile FileName
End If
WScript.Sleep 1000
Loop
来源:https://stackoverflow.com/questions/16341402/constantly-look-for-file-when-file-exist-run-command