Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script to check for empty file and wait for 5 minutes and try again if empty

Status
Not open for further replies.

gradmin

MIS
Jul 22, 2009
1
US
Hi all-
I am trying to figure out how to modify the code shown below (it runs in a scheduled task on a server)so that if the file SD_XOG_FILE.xml is empty then the script will pause for 5 minutes and try again. If it is not empty it will output to SD_XOG_OUT_WO.xml. I have tried a lot of things with no luck. THANKS!!!

C:\XOG\BIN\xog -servername TESTSERVER01 -portnumber 80 -username ben -password houseboat1 -input C:\xog\SD_XOG_FILE.xml -output C:\xog\SD_XOG_FILE_OUT_WO.xml
 
Ready fire aim! - shooting from the hip here.
I'm not entirely sure I understand the process. I'm probably just being dense. Here's a function that returns true/false if the file is empty.
Code:
Function FileEmpty(File_Path_Name)

	Const s_ForReading=1
	Const s_ForWriting=2
	
	Dim s_sFileName, s_oFSO
	dim s_sReadFile, s_sFile_Contents

	s_sFileName = File_Path_Name
	
	'wscript.echo "s_sFileName: " & s_sFileName
	
	Set s_oFSO = CreateObject("Scripting.FileSystemObject")
	
	If Not s_oFSO.FileExists(s_sFileName) Then
		 wscript.echo "File '" & s_sFileName & "' does not exist!"
		Exit Sub
	'Else
		'WScript.Echo "File exists"
	End If

	Set s_sReadFile = s_oFSO.OpenTextFile(s_sFileName, s_ForReading, True)
	
	s_sFile_Contents = s_sReadFile.ReadAll
	
	If (Len(s_sFile_Contents) > 0) Then
		wscript.echo "Greater than 0 - appears to have text"
		FileEmpty = False
	Else
		wscript.echo "Not greater than 0 - appears to have no text"
		FileEmpty = True
	End If
	
	Set s_sReadFile = Nothing
	Set s_oFSO = Nothing
End Function

This is likely a place for a do while/do until loop
Code:
if (FileEmpty("C:\xog\SD_XOG_FILE.xml")) Then
	do While FileEmpty("C:\xog\SD_XOG_FILE.xml") = "True"
		wscript.sleep 300000000
	Loop
end if
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top