Sign in to follow this  
Followers 0
quicksilver

Stop that the Program quits while an error

6 posts in this topic

#1 ·  Posted (edited)

Hello i've got written a little program thats look into a folder an Prints all the txt files with a specified program. But now my problem.. when the folder is empty the program quits with this message:

Posted Image

But i want that the program runs endless until it will be closed in the tray

and here the program:

While "0"="0" 

$ini_file  = "dirlist.ini"

$file = FileOpen($ini_file, 0)

; Variablen einlesen
$program = FileReadLine($file,1)
$workdir = FileReadLine($file,2)
$sicherung = FileReadLine($file,3)
$filenames = FileReadLine($file,4)
$sleepzeit = FileReadLine($file,8)
FileClose($file)

$search = FileFindFirstFile($filenames)  

; Check if the search was successful
If $search = -1 Then
  ;MsgBox(0, "Error", "No files/directories matched the search pattern")
  ;Exit
EndIf

While 1
    $file = FileFindNextFile($search) 
    If @error Then ExitLoop
    $execute = $program&" "&$workdir&$file
    $source = $workdir&$file
    $dest = $sicherung&$file
    RunWait($execute,$workdir)
    FileMove($source, $dest)
  ; --- logfile
    $files = FileOpen($ini_file, 0)

; Variablen einlesen
    $pretext = FileReadLine($files,5)
    $logfile = FileReadLine($files,6)
    $aftertext = FileReadLine($files,7)
    FileClose($files)
    $Input_Date = @MDAY & "-" & @MON & "-" & @YEAR
    $Input_Time = @HOUR &  ":" & @MIN & ":" & @SEC
    $thetime = "Datum und Uhrzeit: "&$Input_Date&" - "&$Input_Time&" - "&$file

    $Input_Date_File = @MDAY & "_" & @MON & "_" & @YEAR
    $Input_Time_File = @HOUR &  "_" & @MIN
    $logfilename = $logfile&"log__"&$Input_Date_File&"__"&$Input_Time_File&".txt"
; Logfile Erstellen
    $files = FileOpen($logfilename, 1)
    FileWriteLine($files, $pretext)
    FileWriteLine($files, $thetime)
    FileWriteLine($files, $aftertext) 
    FileClose($files);
  ; --- logfile    


WEnd

; Close the search handle
FileClose($search)

; --------------------------------
$sleepzeit = $sleepzeit*60000
Sleep($sleepzeit) 
WEnd 
Exit

thx for help

Edited by quicksilver

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

when the folder is empty the program quits with this message:

Posted Image

<{POST_SNAPBACK}>

When you run it as Script (Eg. in SciTe) then it shows you at which line the Error occured. If it is compiled then it only shows Line 0.

Try it again. Maybe you'll find your error.

Edit: Ich kann dir sonst auch auf Deutsch helfen wenn es für dich einfacher ist :whistle:

Edited by Raindancer

Say: "Chuchichäschtli"My UDFs:_PrintImage UDF_WinAnimate UDFGruess Raindancer

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

there is no error in the script. The script returns that the path where the files are is empty. After this it quits.. is there any way to stop this?

Edit: Jo :whistle: Also das script gibt nur zurück das der pfad leer ist.. ansonsten geht es ja. wenn dateien im verzeichnis liegen funzt es 1a aber wenn der pfad leer ist beendet sich das programm. Ich müsste einfach die fehlermeldung unterdrücken. Geht das irgendwie?

Edited by quicksilver

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

$search = FileFindFirstFile($filenames)  

; Check if the search was successful
If $search = -1 Then
;MsgBox(0, "Error", "No files/directories matched the search pattern")
;Exit
EndIf
FileFindFirstFile returns -1 when it detects an error (e.g. no files found). You cannot use -1 as a search handle! There is already some code to test that error condition, however, you'll have to do something meaningful.

If $search = -1 Then
    sleep(10000)
    continueloop;-- The outer while loop !!
EndIf

BTW: Is it really necessary to read the INI file within the while loops? Could be done outside of the loops.

Cheers

Kurt

Edited by /dev/null

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

This should work:

While "0"="0" 

$ini_file  = "dirlist.ini"

$file = FileOpen($ini_file, 0)

; Variablen einlesen
$program = FileReadLine($file,1)
$workdir = FileReadLine($file,2)
$sicherung = FileReadLine($file,3)
$filenames = FileReadLine($file,4)
$sleepzeit = FileReadLine($file,8)
FileClose($file)

;$program = "EDI2TXT.EXE"
;$workdir = "C:\Temp\schaefer\import\"
;$sicherung = "C:\Temp\schaefer\save\"
;$filenames = "C:\Temp\schaefer\import\data_*.txt"

$search = FileFindFirstFile($filenames)  

; Check if the search was successful
If Not $search = -1 Then
    While 1
        $file = FileFindNextFile($search) 
        If @error Then ExitLoop
        $execute = $program&" "&$workdir&$file
        $source = $workdir&$file
        $dest = $sicherung&$file
        RunWait($execute,$workdir)
        FileMove($source, $dest)
    ; --- logfile
        $files = FileOpen($ini_file, 0)
    
    ; Variablen einlesen
        $pretext = FileReadLine($files,5)
        $logfile = FileReadLine($files,6)
        $aftertext = FileReadLine($files,7)
        FileClose($files)
        $Input_Date = @MDAY & "-" & @MON & "-" & @YEAR
        $Input_Time = @HOUR &  ":" & @MIN & ":" & @SEC
        $thetime = "Datum und Uhrzeit: "&$Input_Date&" - "&$Input_Time&" - "&$file

        $Input_Date_File = @MDAY & "_" & @MON & "_" & @YEAR
        $Input_Time_File = @HOUR &  "_" & @MIN
        $logfilename = $logfile&"log__"&$Input_Date_File&"__"&$Input_Time_File&".txt"
    ; Logfile Erstellen
        $files = FileOpen($logfilename, 1)
        FileWriteLine($files, $pretext)
        FileWriteLine($files, $thetime)
        FileWriteLine($files, $aftertext) 
        FileClose($files);
; --- logfile
    WEnd
EndIf

; Close the search handle
FileClose($search)

; --------------------------------
$sleepzeit = $sleepzeit*60000
Sleep($sleepzeit) 
WEnd 
Exit

It only runs the inner loop if the folder isn't empty.

Edit: /dev/nulls lösung ist die hübschere von beiden ;-)

Edited by Raindancer

Say: "Chuchichäschtli"My UDFs:_PrintImage UDF_WinAnimate UDFGruess Raindancer

Share this post


Link to post
Share on other sites

Thx :whistle: no it works:) nice job

Danke euch :dance:

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0