不断查找文件,当文件存在时,运行命令 [英] Constantly look for file, when file exist, run command
本文介绍了不断查找文件,当文件存在时,运行命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要一个vbscript来监视特定文件的文件夹,当找到文件时,它需要执行命令,然后删除该文件,但继续监视同一文件的文件夹,以防万一它需要再次运行.
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.
这个...
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
给我一个"object required: file"
错误.
更新,此方法有效...
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
推荐答案
只需创建一个无限循环的脚本,测试文件是否存在以及是否将其删除.
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
这篇关于不断查找文件,当文件存在时,运行命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文