Check for Files

Recommended Posts

I have a script that uses a number of different INI files so when the routine starts I check that they are present. This is the code that I have written

CODE
Global $message = "" ; Check that the INI files still exist ; If Not FileExists(@ScriptDir & "\inifiles\abc.ini") Then plbeep()$message = " ABC.INI FILE NOT AVAIL"

DisplayMessage()

Exit

EndIf

If Not FileExists(@ScriptDir & "\inifiles\def.ini") Then

plbeep()

$message = " DEF.INI NOT AVAIL" DisplayMessage() Exit EndIf ;Message Box Subroutine ; Func DisplayMessage() splashTextOn("PROXLOC",$message , 250, 50, 600, 500, 36, "times new roman", 10, 600)

Sleep(2000)

splashOff()

EndFunc

;Beep Subroutine

;

Func plbeep()

For $i = 4 to 1 Step -1 Beep(500,50) Sleep(100) Next EndFunc Is there a routine where I can code a list of files and have each file on the list checked that it exists rather than a routine which sequentially checks each inifile as I have written Help is appreciated Ant.. Share this post Link to post Share on other sites I have a script that uses a number of different INI files so when the routine starts I check that they are present. This is the code that I have written CODE Global$message = ""

; Check that the INI files still exist

;

If Not FileExists(@ScriptDir & "\inifiles\abc.ini") Then

plbeep()

$message = " ABC.INI FILE NOT AVAIL" DisplayMessage() Exit EndIf If Not FileExists(@ScriptDir & "\inifiles\def.ini") Then plbeep()$message = " DEF.INI NOT AVAIL"

DisplayMessage()

Exit

EndIf

;Message Box Subroutine

;

Func DisplayMessage()

splashTextOn("PROXLOC", $message , 250, 50, 600, 500, 36, "times new roman", 10, 600) Sleep(2000) splashOff() EndFunc ;Beep Subroutine ; Func plbeep() For$i = 4 to 1 Step -1

Beep(500,50)

Sleep(100)

Next

EndFunc

Is there a routine where I can code a list of files and have each file on the list checked that it exists rather than a routine which sequentially checks each

inifile as I have written

Help is appreciated

Ant..

Not sure exactly what you want but maybe you can use this and create an Array of the file names and then call the func as many times as needed to check if the file does not exist.

Global $file01 = "\inifiles\abc.ini" _runINI($file01)

Func _runINI($filename) If Not FileExists(@ScriptDir &$filename) Then
plbeep()
$message =$filename & " FILE NOT AVAIL"
DisplayMessage()
Exit
EndIf
EndFunc

NOTE - code not tested

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go."

"Everybody catches up with everyone, eventually"

"As you teach others, you are really teaching yourself."

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with$__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share on other sites

Not sure exactly what you want but maybe you can use this and create an Array of the file names and then call the func as many times as needed to check if the file does not exist.

Global $file01 = "\inifiles\abc.ini" _runINI($file01)

Func _runINI($filename) If Not FileExists(@ScriptDir &$filename) Then
plbeep()
$message =$filename & " FILE NOT AVAIL"
DisplayMessage()
Exit
EndIf
EndFunc

I have no experience with an array I can see that this routine will check for abc.ini but what would the code look like if the next file to check is def.ini and then ghi.ini etc etc

Ant..

NOTE - code not tested

Share on other sites

This works but I am not sure that this is smart code

CODE
Global $file01 = "\inifiles\abc.ini" Global$file02 = "\inifiles\def.ini"

Global $file03 = "\inifiles\ghi.ini" _runINI($file01)

_runINI($file02) _runINI($file03)

Func _runINI($filename) If Not FileExists(@ScriptDir &$filename) Then

plbeep()

$message =$filename & " FILE NOT AVAIL"

DisplayMessage()

Exit

EndIf

EndFunc

;Message Box Subroutine

;

Func DisplayMessage()

splashTextOn("PROXLOC", $message , 250, 50, 600, 500, 36, "times new roman", 10, 600) Sleep(2000) splashOff() EndFunc ;Beep Subroutine ; Func plbeep()$beep = IniRead(@ScriptDir&"\inifiles\proxloc.ini", "stealth", "plmonitorab", "0")

If $beep = 1 Then For$i = 4 to 1 Step -1

Beep(500,50)

Sleep(100)

Next

Endif

EndFunc

What do you think?

cheers

Ant...

Edited by anixon

Share on other sites

This works but I am not sure that this is smart code

CODE
Global $file01 = "\inifiles\abc.ini" Global$file02 = "\inifiles\def.ini"

Global $file03 = "\inifiles\ghi.ini" _runINI($file01)

_runINI($file02) _runINI($file03)

Func _runINI($filename) If Not FileExists(@ScriptDir &$filename) Then

plbeep()

$message =$filename & " FILE NOT AVAIL"

DisplayMessage()

Exit

EndIf

EndFunc

;Message Box Subroutine

;

Func DisplayMessage()

splashTextOn("PROXLOC", $message , 250, 50, 600, 500, 36, "times new roman", 10, 600) Sleep(2000) splashOff() EndFunc ;Beep Subroutine ; Func plbeep()$beep = IniRead(@ScriptDir&"\inifiles\proxloc.ini", "stealth", "plmonitorab", "0")

If $beep = 1 Then For$i = 4 to 1 Step -1

Beep(500,50)

Sleep(100)

Next

Endif

EndFunc

What do you think?

cheers

Ant...

Again code not tested - I also added the parameter needed to display the message - see if this works

Global $file[4] = ["\inifiles\abc.ini","\inifiles\def.ini","\inifiles\ghi.ini"] For$i = 1 to UBound($file) - 1 _runINI($file[$i]) Next Func _runINI($filename)
If Not FileExists(@ScriptDir & $filename) Then plbeep()$message = $filename & " FILE NOT AVAIL" DisplayMessage($message)
Exit
EndIf
EndFunc

;Message Box Subroutine
;
Func DisplayMessage($message) splashTextOn("PROXLOC",$message , 250, 50, 600, 500, 36, "times new roman", 10, 600)
Sleep(2000)
splashOff()
EndFunc

;Beep Subroutine
;
Func plbeep()
$beep = IniRead(@ScriptDir&"\inifiles\proxloc.ini", "stealth", "plmonitorab", "0") If$beep = 1 Then
For $i = 4 to 1 Step -1 Beep(500,50) Sleep(100) Next Endif EndFunc EDIT I think you may want to check the other file proxloc.ini before you use it - just to keep your code from doing unexpected things Edited by nitekram All by me: "Sometimes you have to go back to where you started, to get to where you want to go." "Everybody catches up with everyone, eventually" "As you teach others, you are really teaching yourself." From my dad "Do not worry about yesterday, as the only thing that you can control is tomorrow." Programming Tips Excel Changes ControlHover.UDF GDI_Plus Draw_On_Screen GDI Basics GDI_More_Basics GDI Rotate GDI Graph GDI CheckExistingItems GDI Trajectory Replace$ghGDIPDll with $__g_hGDIPDll DLL 101? Array via Object GDI Swimlane GDI Plus French 101 Site GDI Examples UEZ GDI Basic Clock GDI Detection Ternary operator Share this post Link to post Share on other sites Again code not tested - I also added the parameter needed to display the message - see if this works Global$file[4] = ["\inifiles\abc.ini","\inifiles\def.ini","\inifiles\ghi.ini"]

For $i = 1 to UBound($file) - 1
_runINI($file[$i])
Next

Func _runINI($filename) If Not FileExists(@ScriptDir &$filename) Then
plbeep()
$message =$filename & " FILE NOT AVAIL"
DisplayMessage($message) Exit EndIf EndFunc ;Message Box Subroutine ; Func DisplayMessage($message)
splashTextOn("PROXLOC", $message , 250, 50, 600, 500, 36, "times new roman", 10, 600) Sleep(2000) splashOff() EndFunc ;Beep Subroutine ; Func plbeep()$beep = IniRead(@ScriptDir&"\inifiles\proxloc.ini", "stealth", "plmonitorab", "0")
If $beep = 1 Then For$i = 4 to 1 Step -1
Beep(500,50)
Sleep(100)
Next
Endif
EndFunc

EDIT

I think you may want to check the other file proxloc.ini before you use it - just to keep your code from doing unexpected things

I did the mod to plbeep to get rid of the $beep reference to proxloc but have been unable to make your code work as$filename appears not to be getting a value and I have no Idea how to fix it.

Cheers Ant..

Share on other sites

I have a script that uses a number of different INI files so when the routine starts I check that they are present. This is the code that I have written

CODE
Global $message = "" ; Check that the INI files still exist ; If Not FileExists(@ScriptDir & "\inifiles\abc.ini") Then plbeep()$message = " ABC.INI FILE NOT AVAIL"

DisplayMessage()

Exit

EndIf

If Not FileExists(@ScriptDir & "\inifiles\def.ini") Then

plbeep()

$message = " DEF.INI NOT AVAIL" DisplayMessage() Exit EndIf ;Message Box Subroutine ; Func DisplayMessage() splashTextOn("PROXLOC",$message , 250, 50, 600, 500, 36, "times new roman", 10, 600)

Sleep(2000)

splashOff()

EndFunc

;Beep Subroutine

;

Func plbeep()

Cheers Ant...

Share on other sites

I have fully tested your code and for some reason it does not check the first item "\inifiles\abc.ini" works fine if def.ini or ghi.ini don't exist.

This is the line of code that may be at issue

Global $file[4] = ["\inifiles\abc.ini","\inifiles\def.ini","\inifiles\ghi.ini"] Cheers Ant... Ahh success to resolve the above in the code statement For$i = 1 to UBound($file) - 1 _runINI($file[$i]) Next$i = 1 should be changed to $i = 0 Cheers Ant.. Share this post Link to post Share on other sites Ahh success to resolve the above in the code statement For$i = 1 to UBound($file) - 1 _runINI($file[$i]) Next$i = 1 should be changed to $i = 0 Cheers Ant.. This is another adaptation of the UBound code which will close running applications CODE ;Close any running Progams ; Global$file[4] = ["abc.exe","def.exe","ghi.exe"]

For $i = 0 to UBound($file) - 1

_closePROG($file[$i])

Next

Func _closePROG($filename)$PID = ProcessExists($filename) If$PID Then ProcessClose(\$PID)

EndFunc

Cheers Ant..

Create an account

Register a new account