Access.2007.VBA.Bibl..

(John Hannent) #1
strFile = “aadownload.log”
strFilePath = strPath & strFile
If fso.FileExists(strFilePath) Then
fso.DeleteFile strFilePath
blnFound = True
End If

strFile = “aaschedule.log”
strFilePath = strPath & strFile
If fso.FileExists(strFilePath) Then
fso.DeleteFile strFilePath
blnFound = True
End If

strFile = “aasubsschedule.log”
strFilePath = strPath & strFile
If fso.FileExists(strFilePath) Then
fso.DeleteFile strFilePath
blnFound = True
End If

If blnFound = True Then
MsgBox “Deleted Audible temp files”
Else
MsgBox “No Audible temp files found”
End If

The script first sets a blnFoundvariable to False(it would be a Boolean variable, if variables
could be declared with data types in VBS). Then the script uses the FileExistsmethod of the
FileSystemObjectto determine whether a file exists, and delete it if so, setting blnFoundto
True. At the end of the code, depending on whether the blnFoundvariable is Trueor False, a
message box appears saying either “Deleted Audible temp files” or “No Audible temp files found.”


You probably don’t need the Delete Audible Files.vbs script, but you may find the Delete Temp
Files.vbs script useful. This script uses the GetSpecialFoldermethod of the
FileSystemObject, with the 2 argument, to set a fldTempvariable to the Temp file folder,
and puts up a message box that asks if you want to delete all files in it; if you click the Yes button,
the script attempts to delete all the files in that folder (the On Error Resume Nextstatement
goes to the next file if a file can’t be deleted, because it is in use):


Dim fso
Dim fldTemp
Dim fil
Dim n
Dim intResult
Dim strPrompt

Creating Standalone Scripts with Windows Script Host 17

Free download pdf