Sign in to follow this  
Followers 0
Frankie Paul

Logging to a file

8 posts in this topic

hey boys i new to the forms and using atuoit they got me using it to test progams and atuff anyways i have a probelem....

what i wanna do is creat a logger which will log my actiong as i do them the probelem is i have to log it to a file that is created using a func with 3 case to it

1. case one is a promte for the file name and dir

2 case two is suplying the dir and name with in the arguments of the func

3. case three is save the file with the date as the name and in the script dir

is there anyways i can log an infanate amout of time using a func and supling what to write as the argument of the func with these 3 case still working please let me know

using FileOpen u can only log 64 time and i need it to log for 3 day millions of actions so i am stuck there

if u can help i would greatly need

thaxs,

frankie Paul


ƒrankie Paul

Share this post


Link to post
Share on other sites



The script below is one I wrote for copying jobs to another machine, it made a log and purged the log, although not exactly what your after you can take most of my logging code and use it,The contents of the ini file to help you understand it better are below too

CODE

$g_szVersion = "Uploader Client 1.1 - tic"

If WinExists($g_szVersion) Then Exit ; It's already running

AutoItWinSetTitle($g_szVersion)

AutoITSetOption ("TrayAutoPause","0")

ProcessSetPriority ( @scriptname, 1)

#include <Date.au3>

#include <file.au3>

#include <array.au3>

#include <GUIConstants.au3>

$sPath = iniread ("Upload.ini", "general", "SourcePath", "d:\upload\")

$dPath = iniread ("Upload.ini", "general", "DestinationPath","\\Labserver\upload\")

$PollingTime = iniread ("Upload.ini", "general", "Pollingtime","5")

$RetryTime = iniread ("Upload.ini", "general", "Retrytime","20")

$MachineID = iniread ("Upload.ini", "general", "MachineID","0000")

$Days = iniread ("Upload.ini", "general", "DaysToKeep","2")

$Logging = StringLower (iniread ("Upload.ini", "general", "logging","no"))

$LinestoKeep = iniread ("Upload.ini", "general", "LinesToKeep","500")

$LinestoPurge = iniread ("Upload.ini", "general", "Purge","50")

If StringRight($sPath, 1) <> '\' Then $sPath = $sPath & '\'

If StringRight($dPath, 1) <> '\' Then $dPath = $dPath & '\'

$Waiting = 0

$Source = _ArrayCreate ("0","0")

$Destination = _ArrayCreate ("1","1")

;create directories

GUICreate ( "Upload" , 500 , 50 , -1 , -1 , $WS_POPUP )

$Text = GUICtrlCreateLabel ( "Starting", 10, 20 , 490 , 20 , $SS_CENTER)

GUISetState ()

if not FileExists ($spath) Then

MsgBox (0,"Warning", "The local Job folder " & $sPath & " Does not exsits" & @crlf & "The Directory will be created", 10)

DirCreate ($spath)

DirCreate ($sPath & "\Error")

DirCreate ($sPath & "\Done")

logging ("Hot path did not exist creating " & $sPath)

logging ("Hot path did not exist creating " & $sPath & "\Error")

logging ("Hot path did not exist creating " & $sPath & "\Done")

Endif

Process()

Func Process()

While 1

$Source[0]="0"

$Source[1]="0"

$Destination[0] = "1"

$Destination[1] = "1"

$fileHandle = fileFindFirstFile($sPath & "*.lac")

if $FileHandle = -1 then $fileHandle = fileFindFirstFile($sPath & "*.lax")

if ($fileHandle <> -1) then

if (@error = 1) then

Else

$file = fileFindNextFile($fileHandle)

ENDIF

if ($file = "." or $file = "..") then

Else

$Folder = StringtrimRight ($File, 4)

Endif

FileClose($FileHandle)

GUICtrlSetData ($Text, "Found File " & $File)

;logging ("Found File " & $File)

;Check upload path

If FileExists ($dPath) then

GUICtrlSetData ($Text, "Path " & $dPath & "Exists")

;MsgBox (0,"",$sPath & $Folder & " " & $dPath & $Folder)

If FileExists ($sPath & $Folder) then

$Source = DirGetSize( $sPath & $Folder ,1)

logging ("Source size, Total file size " & $Source[0] & " - Total File count "& $Source[1])

GUICtrlSetData ($Text, "Copying " & $sPath & $Folder & " to " & $dPath & $MachineID & "\" & $Folder )

logging ("Copying " & $sPath & $Folder & " to " & $dPath & $Folder)

DirCreate ($dPath)

DirCopy ( $sPath & "\" & $Folder, $dPath & $machineID & "\" & $Folder , 1)

If FileExists ($dPath & $MachineID & "\" & $Folder ) then

$Destination = DirGetSize( $dPath & $MachineID & "\" & $Folder ,1)

logging ("Destination size, Total file size " & $Destination[0] & " - Total File count "& $Destination[1])

Else

$Destination[0] = "1"

$Destination[1] = "1"

;_ArrayDisplay ($Destination,"")

Endif

Else

DirCreate ($sPath & "Error")

FileMove ($sPath & $File, $sPath & "Error\", 1)

logging ("Can not find source folder " & $sPath & "\" & $Folder & " Moving file to error folder")

GUICtrlSetData ($Text, "Can not find source folder " & $sPath & "\" & $Folder & " Moving file to error folder")

Endif

If FileExists ($sPath & $Folder) then

If $Source[1] = $Destination[1] then

GUICtrlSetData ($Text, "Upload size matched Moving " & $sPath & $Folder & " to done")

logging ("Upload size matched Moving " & $sPath & $Folder & " to done")

$FileNameSplit = StringSplit ($File, ".")

logging ("Copying " & $dPath & $FileNameSplit[1] & $MachineID & "." & $FileNameSplit[2])

FileCopy ($sPath & $File, $dPath & $FileNameSplit[1] & $MachineID & "." & $FileNameSplit[2] , 1)

;MSgBox (0,"File", $dPath & "\" & $FileNameSplit[1] & $MachineID & "." & $FileNameSplit[2])

DirCreate ($sPath & "done\")

FileSetAttrib ( $sPath & $Folder, "-R" , 1 )

FileSetAttrib ( $sPath & $File, "-R" , 1 )

logging ("Moving " & $sPath & $Folder & " to " & $sPath & "done\")

DirMove ($sPath & $Folder, $sPath & "done\", 1)

logging ("Moving " & $sPath & $File & " to " & $sPath & "done\")

FileMove ($sPath & $File, $sPath & "done\", 1)

logging ("Complete ######")

Endif

Else

endif

Else

logging ("Found File " & $File & " but can not find " & $dPath & " Waiting " & $Retrytime)

GUICtrlSetData ($Text, "Can not find " & $dPath & " Waiting ")

For $i = $RetryTime to 0 step -1

sleep(1000)

GUICtrlSetData ($Text, "Can not find " & $dPath & " Retry in "& $i)

$Waiting = 1

Next

endif

DirCreate ($sPath & "Error")

endif

If not $Waiting = 1 then

For $i = $PollingTime to 0 step -1

sleep(1000)

GUICtrlSetData ($Text, "Idle - Local Directory is " & $sPath & " Re-check in "& $i)

$Waiting = 1

Next

cleaner()

Endif

$Waiting = 0

Wend

FileClose ($FileHandle)

EndFunc

Func Cleaner()

$CurrentTimeStamp = @year & "/" & @mon &"/" & @mday

FileSetAttrib ( $sPath & "Done", "-R" , 1 )

$cleanHandle = fileFindFirstFile($sPath & "Done\*.lac")

if $cleanHandle = -1 then $cleanHandle = fileFindFirstFile($sPath & "Done\*.lax")

if ($cleanHandle <> -1) then

if (@error = 1) then

Else

$cleanfile = fileFindNextFile($cleanHandle)

ENDIF

if ($cleanfile = "." or $cleanfile = "..") then

Else

$cleanFolder = StringtrimRight ($cleanFile, 4)

$filetime = StringtrimRight (FileGetTime ( $sPath & "Done\" & $cleanFile , 0 , 1 ),6)

$Filetimeyear = Stringtrimright ($filetime,4)

$FileMd = Stringtrimleft ($filetime,4)

$FileTimeMonth = Stringtrimright ($fileMD,2)

$FileTimeDay = Stringtrimleft ($fileMD,2)

$Comparedate = $FileTimeYear & "/" & $FileTimeMonth & "/" & $FiletimeDay

$DaysDiff = _DateDiff("D", $CompareDate, $CurrentTimeStamp)

;MSgBox (0,$CurrentTimeStamp, $CompareDate)

;MSgBox (0,$CleanFile, $DaysDiff)

If $Cleanhandle <> -1 and $DaysDiff >= $Days Then

GUICtrlSetData ($Text, "Cleaning old files " & $CleanFolder)

IF FileExists ($sPath & "Done\" & $CleanFolder) then DirRemove ( $sPath & "Done\" & $CleanFolder , 1)

IF FileExists ($sPath & "Done\" & $CleanFile) then FileDelete ( $sPath & "Done\" & $CleanFile )

cleanlog ("Cleaning old files " & $CleanFolder & ": Files are " & $DaysDiff & " Old")

Endif

Endif

FileClose($cleanHandle)

Endif

Endfunc

Func Logging ($logtext)

If $logging = "yes" Then

;MsgBox (0,"Logging", $Logtext)

if not FileExists ("uploadlog.txt") then

$logfile = FileOpen ("uploadlog.txt",1)

Fileclose ($logfile)

endif

loglength ("uploadlog.txt")

$logfile = FileOpen ("uploadlog.txt",1)

FileWriteLine($logfile, $logtext & " - " & @mday & "/" & @mon & "/" & @year & " - " & @hour & ":" & @min)

Fileclose ($logfile)

Endif

Endfunc

Func Cleanlog ($clogtext)

If $logging = "yes" Then

;MsgBox (0,"Cleaning", $clogtext)

if not FileExists ("cleanlog.txt") then

$clogfile = FileOpen ("cleanlog.txt",1)

Fileclose ($clogfile)

endif

loglength ("cleanlog.txt")

$clogfile = FileOpen ("cleanlog.txt",1)

FileWriteLine($clogfile, $clogtext & " - " & @mday & "/" & @mon & "/" & @year & " - " & @hour & ":" & @min)

Fileclose ($clogfile)

Endif

EndFunc

Func loglength($Logfile)

$LogLineCount = _FileCountLines( $Logfile )

$File = FileOpen ( $Logfile, 0)

If $LogLineCount > $LinestoKeep Then

$Newfile = FileOPen ("log.tmp", 1)

;MsgBox (0,"Line Count", $LogLineCount)

$Linecount = 0

While 1

$line = FileReadLine($File)

If @error = -1 Then ExitLoop

$Linecount = $linecount + 1

IF $Linecount < ($LinestoPurge + $linesToKeep) then

;do nothing but wait until Filewriteline to copy original text to tmp file deleteg 50 lines from the top

else

FileWriteLine ($NewFile, $Line)

Endif

Wend

FileClose ( $File )

FileClose ( $NewFile )

FileDelete ( $Logfile )

FileMove("log.tmp", $Logfile)

else

FileClose ( $File )

Endif

Endfunc

Inifile contents

[General]

SourcePath=d:\hotq\123401\

DestinationPath=\\Bay2server\hotq\

PollingTime=5

RetryTime=6

MachineID=123401

DaysToKeep=2

Logging=yes

LinesToKeep=1000

Purge=100

Share this post


Link to post
Share on other sites

Up to 64 files can be opened at once. You can write to the file more than 64 times.

Man ya thanks if u didn't wanna help should have never replyed how do i write to a file and not open it then ???

ƒrankie Paul

Share this post


Link to post
Share on other sites

The script below is one I wrote for copying jobs to another machine, it made a log and purged the log, although not exactly what your after you can take most of my logging code and use it,The contents of the ini file to help you understand it better are below too

CODE

$g_szVersion = "Uploader Client 1.1 - tic"

If WinExists($g_szVersion) Then Exit ; It's already running

AutoItWinSetTitle($g_szVersion)

AutoITSetOption ("TrayAutoPause","0")

ProcessSetPriority ( @scriptname, 1)

#include <Date.au3>

#include <file.au3>

#include <array.au3>

#include <GUIConstants.au3>

$sPath = iniread ("Upload.ini", "general", "SourcePath", "d:\upload\")

$dPath = iniread ("Upload.ini", "general", "DestinationPath","\\Labserver\upload\")

$PollingTime = iniread ("Upload.ini", "general", "Pollingtime","5")

$RetryTime = iniread ("Upload.ini", "general", "Retrytime","20")

$MachineID = iniread ("Upload.ini", "general", "MachineID","0000")

$Days = iniread ("Upload.ini", "general", "DaysToKeep","2")

$Logging = StringLower (iniread ("Upload.ini", "general", "logging","no"))

$LinestoKeep = iniread ("Upload.ini", "general", "LinesToKeep","500")

$LinestoPurge = iniread ("Upload.ini", "general", "Purge","50")

If StringRight($sPath, 1) <> '\' Then $sPath = $sPath & '\'

If StringRight($dPath, 1) <> '\' Then $dPath = $dPath & '\'

$Waiting = 0

$Source = _ArrayCreate ("0","0")

$Destination = _ArrayCreate ("1","1")

;create directories

GUICreate ( "Upload" , 500 , 50 , -1 , -1 , $WS_POPUP )

$Text = GUICtrlCreateLabel ( "Starting", 10, 20 , 490 , 20 , $SS_CENTER)

GUISetState ()

if not FileExists ($spath) Then

MsgBox (0,"Warning", "The local Job folder " & $sPath & " Does not exsits" & @crlf & "The Directory will be created", 10)

DirCreate ($spath)

DirCreate ($sPath & "\Error")

DirCreate ($sPath & "\Done")

logging ("Hot path did not exist creating " & $sPath)

logging ("Hot path did not exist creating " & $sPath & "\Error")

logging ("Hot path did not exist creating " & $sPath & "\Done")

Endif

Process()

Func Process()

While 1

$Source[0]="0"

$Source[1]="0"

$Destination[0] = "1"

$Destination[1] = "1"

$fileHandle = fileFindFirstFile($sPath & "*.lac")

if $FileHandle = -1 then $fileHandle = fileFindFirstFile($sPath & "*.lax")

if ($fileHandle <> -1) then

if (@error = 1) then

Else

$file = fileFindNextFile($fileHandle)

ENDIF

if ($file = "." or $file = "..") then

Else

$Folder = StringtrimRight ($File, 4)

Endif

FileClose($FileHandle)

GUICtrlSetData ($Text, "Found File " & $File)

;logging ("Found File " & $File)

;Check upload path

If FileExists ($dPath) then

GUICtrlSetData ($Text, "Path " & $dPath & "Exists")

;MsgBox (0,"",$sPath & $Folder & " " & $dPath & $Folder)

If FileExists ($sPath & $Folder) then

$Source = DirGetSize( $sPath & $Folder ,1)

logging ("Source size, Total file size " & $Source[0] & " - Total File count "& $Source[1])

GUICtrlSetData ($Text, "Copying " & $sPath & $Folder & " to " & $dPath & $MachineID & "\" & $Folder )

logging ("Copying " & $sPath & $Folder & " to " & $dPath & $Folder)

DirCreate ($dPath)

DirCopy ( $sPath & "\" & $Folder, $dPath & $machineID & "\" & $Folder , 1)

If FileExists ($dPath & $MachineID & "\" & $Folder ) then

$Destination = DirGetSize( $dPath & $MachineID & "\" & $Folder ,1)

logging ("Destination size, Total file size " & $Destination[0] & " - Total File count "& $Destination[1])

Else

$Destination[0] = "1"

$Destination[1] = "1"

;_ArrayDisplay ($Destination,"")

Endif

Else

DirCreate ($sPath & "Error")

FileMove ($sPath & $File, $sPath & "Error\", 1)

logging ("Can not find source folder " & $sPath & "\" & $Folder & " Moving file to error folder")

GUICtrlSetData ($Text, "Can not find source folder " & $sPath & "\" & $Folder & " Moving file to error folder")

Endif

If FileExists ($sPath & $Folder) then

If $Source[1] = $Destination[1] then

GUICtrlSetData ($Text, "Upload size matched Moving " & $sPath & $Folder & " to done")

logging ("Upload size matched Moving " & $sPath & $Folder & " to done")

$FileNameSplit = StringSplit ($File, ".")

logging ("Copying " & $dPath & $FileNameSplit[1] & $MachineID & "." & $FileNameSplit[2])

FileCopy ($sPath & $File, $dPath & $FileNameSplit[1] & $MachineID & "." & $FileNameSplit[2] , 1)

;MSgBox (0,"File", $dPath & "\" & $FileNameSplit[1] & $MachineID & "." & $FileNameSplit[2])

DirCreate ($sPath & "done\")

FileSetAttrib ( $sPath & $Folder, "-R" , 1 )

FileSetAttrib ( $sPath & $File, "-R" , 1 )

logging ("Moving " & $sPath & $Folder & " to " & $sPath & "done\")

DirMove ($sPath & $Folder, $sPath & "done\", 1)

logging ("Moving " & $sPath & $File & " to " & $sPath & "done\")

FileMove ($sPath & $File, $sPath & "done\", 1)

logging ("Complete ######")

Endif

Else

endif

Else

logging ("Found File " & $File & " but can not find " & $dPath & " Waiting " & $Retrytime)

GUICtrlSetData ($Text, "Can not find " & $dPath & " Waiting ")

For $i = $RetryTime to 0 step -1

sleep(1000)

GUICtrlSetData ($Text, "Can not find " & $dPath & " Retry in "& $i)

$Waiting = 1

Next

endif

DirCreate ($sPath & "Error")

endif

If not $Waiting = 1 then

For $i = $PollingTime to 0 step -1

sleep(1000)

GUICtrlSetData ($Text, "Idle - Local Directory is " & $sPath & " Re-check in "& $i)

$Waiting = 1

Next

cleaner()

Endif

$Waiting = 0

Wend

FileClose ($FileHandle)

EndFunc

Func Cleaner()

$CurrentTimeStamp = @year & "/" & @mon &"/" & @mday

FileSetAttrib ( $sPath & "Done", "-R" , 1 )

$cleanHandle = fileFindFirstFile($sPath & "Done\*.lac")

if $cleanHandle = -1 then $cleanHandle = fileFindFirstFile($sPath & "Done\*.lax")

if ($cleanHandle <> -1) then

if (@error = 1) then

Else

$cleanfile = fileFindNextFile($cleanHandle)

ENDIF

if ($cleanfile = "." or $cleanfile = "..") then

Else

$cleanFolder = StringtrimRight ($cleanFile, 4)

$filetime = StringtrimRight (FileGetTime ( $sPath & "Done\" & $cleanFile , 0 , 1 ),6)

$Filetimeyear = Stringtrimright ($filetime,4)

$FileMd = Stringtrimleft ($filetime,4)

$FileTimeMonth = Stringtrimright ($fileMD,2)

$FileTimeDay = Stringtrimleft ($fileMD,2)

$Comparedate = $FileTimeYear & "/" & $FileTimeMonth & "/" & $FiletimeDay

$DaysDiff = _DateDiff("D", $CompareDate, $CurrentTimeStamp)

;MSgBox (0,$CurrentTimeStamp, $CompareDate)

;MSgBox (0,$CleanFile, $DaysDiff)

If $Cleanhandle <> -1 and $DaysDiff >= $Days Then

GUICtrlSetData ($Text, "Cleaning old files " & $CleanFolder)

IF FileExists ($sPath & "Done\" & $CleanFolder) then DirRemove ( $sPath & "Done\" & $CleanFolder , 1)

IF FileExists ($sPath & "Done\" & $CleanFile) then FileDelete ( $sPath & "Done\" & $CleanFile )

cleanlog ("Cleaning old files " & $CleanFolder & ": Files are " & $DaysDiff & " Old")

Endif

Endif

FileClose($cleanHandle)

Endif

Endfunc

Func Logging ($logtext)

If $logging = "yes" Then

;MsgBox (0,"Logging", $Logtext)

if not FileExists ("uploadlog.txt") then

$logfile = FileOpen ("uploadlog.txt",1)

Fileclose ($logfile)

endif

loglength ("uploadlog.txt")

$logfile = FileOpen ("uploadlog.txt",1)

FileWriteLine($logfile, $logtext & " - " & @mday & "/" & @mon & "/" & @year & " - " & @hour & ":" & @min)

Fileclose ($logfile)

Endif

Endfunc

Func Cleanlog ($clogtext)

If $logging = "yes" Then

;MsgBox (0,"Cleaning", $clogtext)

if not FileExists ("cleanlog.txt") then

$clogfile = FileOpen ("cleanlog.txt",1)

Fileclose ($clogfile)

endif

loglength ("cleanlog.txt")

$clogfile = FileOpen ("cleanlog.txt",1)

FileWriteLine($clogfile, $clogtext & " - " & @mday & "/" & @mon & "/" & @year & " - " & @hour & ":" & @min)

Fileclose ($clogfile)

Endif

EndFunc

Func loglength($Logfile)

$LogLineCount = _FileCountLines( $Logfile )

$File = FileOpen ( $Logfile, 0)

If $LogLineCount > $LinestoKeep Then

$Newfile = FileOPen ("log.tmp", 1)

;MsgBox (0,"Line Count", $LogLineCount)

$Linecount = 0

While 1

$line = FileReadLine($File)

If @error = -1 Then ExitLoop

$Linecount = $linecount + 1

IF $Linecount < ($LinestoPurge + $linesToKeep) then

;do nothing but wait until Filewriteline to copy original text to tmp file deleteg 50 lines from the top

else

FileWriteLine ($NewFile, $Line)

Endif

Wend

FileClose ( $File )

FileClose ( $NewFile )

FileDelete ( $Logfile )

FileMove("log.tmp", $Logfile)

else

FileClose ( $File )

Endif

Endfunc

Inifile contents

[General]

SourcePath=d:\hotq\123401\

DestinationPath=\\Bay2server\hotq\

PollingTime=5

RetryTime=6

MachineID=123401

DaysToKeep=2

Logging=yes

LinesToKeep=1000

Purge=100

Thank you budddy This did work for me and i did find another way 2 do it that a lil shorter... what excatly did u use it for thought i was wondering ?


ƒrankie Paul

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Man ya thanks if u didn't wanna help should have never replyed how do i write to a file and not open it then ???

:geek: Another slating and then thanks.

First off I was pointing out the error of your understanding then... I went to have a look through some of my codes to find the solution for you which was actually being helpful, I never said don't open a file I said you can only have 64 files open at once if your gonna insult me at least read what I wrote.

And to your second question...

My script was so long because of the checking of the transfer of the file and the log purging as I was only interested in keeping 100 entries, also it removed jobs after a set period of time after transfer.

It was to get a job from a kiosk and upload the job to another machine, it had all of the retry options because of the limited possible connections into the receiving server and the logging was there to check for failed/successful transfers.

Oh and your welcome :o

Edited by ChrisL

Share this post


Link to post
Share on other sites

I actually had fun with my logging, my output looks like this:

[2/22/2006][8:24:46 PM] Starting Up...

[2/22/2006][8:24:50 PM] Logging In...

[2/22/2006][8:24:59 PM] Logged In...

[2/22/2006][8:25:05 PM] [Number 1] Sent Priviate Message To Member #27000046

[2/22/2006][8:25:12 PM] [Number 2] Sent Priviate Message To Member #27000047

[2/22/2006][8:25:20 PM] [Number 3] Sent Priviate Message To Member #27000053

[2/22/2006][8:25:27 PM] [Number 4] Sent Priviate Message To Member #27000061

and the line of code is just:

FileWriteLine($file, "[" & _NowDate() & "][" & _NowTime() & "] [Number " & $Runs & "] Sent Priviate Message To Member #" & $FRIENDNUMBER)

NOTE: you need beta for the time and date or just paste these functions into your script:

Func _NowDate()
    Return (_DateTimeFormat(@YEAR & "/" & @MON & "/" & @MDAY, 0))
EndFunc  ;==>_NowDate
Func _DateMonthOfYear($iMonthNum, $iShort)
;==============================================
; Local Constant/Variable Declaration Section
;==============================================
    Local $aMonthOfYear[13]
    
    $aMonthOfYear[1] = "January"
    $aMonthOfYear[2] = "February"
    $aMonthOfYear[3] = "March"
    $aMonthOfYear[4] = "April"
    $aMonthOfYear[5] = "May"
    $aMonthOfYear[6] = "June"
    $aMonthOfYear[7] = "July"
    $aMonthOfYear[8] = "August"
    $aMonthOfYear[9] = "September"
    $aMonthOfYear[10] = "October"
    $aMonthOfYear[11] = "November"
    $aMonthOfYear[12] = "December"
    
    Select
        Case Not StringIsInt($iMonthNum) Or Not StringIsInt($iShort)
            SetError(1)
            Return ""
        Case $iMonthNum < 1 Or $iMonthNum > 12
            SetError(1)
            Return ""
        Case Else
            Select
                Case $iShort = 0
                    Return $aMonthOfYear[$iMonthNum]
                Case $iShort = 1
                    Return StringLeft($aMonthOfYear[$iMonthNum], 3)
                Case Else
                    SetError(1)
                    Return ""
            EndSelect
    EndSelect
EndFunc  ;==>_DateMonthOfYear
Func _DateDayOfWeek($iDayNum, $iShort = 0)
;==============================================
; Local Constant/Variable Declaration Section
;==============================================
    Local $aDayOfWeek[8]
    
    $aDayOfWeek[1] = "Sunday"
    $aDayOfWeek[2] = "Monday"
    $aDayOfWeek[3] = "Tuesday"
    $aDayOfWeek[4] = "Wednesday"
    $aDayOfWeek[5] = "Thursday"
    $aDayOfWeek[6] = "Friday"
    $aDayOfWeek[7] = "Saturday"
    Select
        Case Not StringIsInt($iDayNum) Or Not StringIsInt($iShort)
            SetError(1)
            Return ""
        Case $iDayNum < 1 Or $iDayNum > 7
            SetError(1)
            Return ""
        Case Else
            Select
                Case $iShort = 0
                    Return $aDayOfWeek[$iDayNum]
                Case $iShort = 1
                    Return StringLeft($aDayOfWeek[$iDayNum], 3)
                Case Else
                    SetError(1)
                    Return ""
            EndSelect
    EndSelect
EndFunc  ;==>_DateDayOfWeek
Func _DateToDayOfWeek($iYear, $iMonth, $iDay)
    Local $i_aFactor
    Local $i_yFactor
    Local $i_mFactor
    Local $i_dFactor
; Verify If InputDate is valid
    If Not _DateIsValid($iYear & "/" & $iMonth & "/" & $iDay) Then
        SetError(1)
        Return ("")
    EndIf
    $i_aFactor = Int((14 - $iMonth) / 12)
    $i_yFactor = $iYear - $i_aFactor
    $i_mFactor = $iMonth + (12 * $i_aFactor) - 2
    $i_dFactor = Mod($iDay + $i_yFactor + Int($i_yFactor / 4) - Int($i_yFactor / 100) + Int($i_yFactor / 400) + Int((31 * $i_mFactor) / 12), 7)
    return ($i_dFactor + 1)
EndFunc  ;==>_DateToDayOfWeek
Func _DateIsLeapYear($iYear)
    If StringIsInt($iYear) Then
        Select
            Case Mod($iYear, 4) = 0 And Mod($iYear, 100) <> 0
                Return 1
            Case Mod($iYear, 400) = 0
                Return 1
            Case Else
                Return 0
        EndSelect
    Else
        SetError(1)
        Return 0
    EndIf
EndFunc  ;==>_DateIsLeapYear
Func _DateTimeSplit($sDate, ByRef $asDatePart, ByRef $iTimePart)
    Local $sDateTime
    Local $x
; split the Date and Time portion
    $sDateTime = StringSplit($sDate, " T")
; split the date portion
    If $sDateTime[0] > 0 Then $asDatePart = StringSplit($sDateTime[1], "/-.")
; split the Time portion
    If $sDateTime[0] > 1 Then
        $iTimePart = StringSplit($sDateTime[2], ":")
        If UBound($iTimePart) < 4 Then ReDim $iTimePart[4]
    Else
        Dim $iTimePart[4]
    EndIf
; Ensure the arrays contain 4 values
    If UBound($asDatePart) < 4 Then ReDim $asDatePart[4]
; update the array to contain numbers not strings
    For $x = 1 To 3
        $asDatePart[$x] = Number($asDatePart[$x])
        $iTimePart[$x] = Number($iTimePart[$x])
    Next
    Return (1)
EndFunc  ;==>_DateTimeSplit
Func _DateIsValid($sDate)
    Local $asDatePart[4]
    Local $asTimePart[4]
    Local $iNumDays
    $iNumDays = "31,28,31,30,31,30,31,31,30,31,30,31"
    $iNumDays = StringSplit($iNumDays, ",")
; split the date and time into arrays
    _DateTimeSplit($sDate, $asDatePart, $asTimePart)
    If $asDatePart[0] <> 3 Then
        Return (0)
    EndIf
; verify valid input date values
    If _DateIsLeapYear($asDatePart[1]) Then $iNumDays[2] = 29
    If $asDatePart[1] < 1900 Or $asDatePart[1] > 2999 Then Return (0)
    If $asDatePart[2] < 1 Or $asDatePart[2] > 12 Then Return (0)
    If $asDatePart[3] < 1 Or $asDatePart[3] > $iNumDays[$asDatePart[2]] Then Return (0)
    
; verify valid input Time values
    If $asTimePart[0] < 1 Then Return (1)   ; No time specified so date must be correct
    If $asTimePart[0] < 2 Then Return (0)   ; need at least HH:MM when something is specified
    If $asTimePart[1] < 0 Or $asTimePart[1] > 23 Then Return (0)
    If $asTimePart[2] < 0 Or $asTimePart[2] > 59 Then Return (0)
    If $asTimePart[3] < 0 Or $asTimePart[3] > 59 Then Return (0)
; we got here so date/time must be good
    Return (1)
EndFunc  ;==>_DateIsValid
Func _DateTimeFormat($sDate, $sType)
    Local $asDatePart[4]
    Local $asTimePart[4]
    Local $sReg_DateValue = ""
    Local $sReg_TimeValue = ""
    Local $sTempDate
    Local $sNewTime
    Local $sNewDate
    Local $sAM
    Local $sPM
    Local $iWday
; Verify If InputDate is valid
    If Not _DateIsValid($sDate) Then
        SetError(1)
        Return ("")
    EndIf
; input validation
    If $sType < 0 Or $sType > 5 Or Not IsInt($sType) Then
        SetError(2)
        Return ("")
    EndIf
; split the date and time into arrays
    _DateTimeSplit($sDate, $asDatePart, $asTimePart)
    
    If $sType = 0 Then
        $sReg_DateValue = "sShortDate"
        If $asTimePart[0] > 1 Then $sReg_TimeValue = "sTimeFormat"
    EndIf
    
    If $sType = 1 Then $sReg_DateValue = "sLongDate"
    If $sType = 2 Then $sReg_DateValue = "sShortDate"
    If $sType = 3 Then $sReg_TimeValue = "sTimeFormat"
    If $sType = 4 Then $sReg_TimeValue = "sTime"
    If $sType = 5 Then $sReg_TimeValue = "sTime"   ; 24 hour clock
    $sNewDate = ""
    If $sReg_DateValue <> "" Then
        $sTempDate = RegRead("HKEY_CURRENT_USER\Control Panel\International", $sReg_DateValue)
        $sAM = RegRead("HKEY_CURRENT_USER\Control Panel\International", "s1159")
        $sPM = RegRead("HKEY_CURRENT_USER\Control Panel\International", "s2359")
        If $sAM = "" Then $sAM = "AM"
        If $sPM = "" Then $sPM = "PM"
        $iWday = _DateToDayOfWeek($asDatePart[1], $asDatePart[2], $asDatePart[3])
        $asDatePart[3] = StringRight("0" & $asDatePart[3], 2); make sure the length is 2
        $asDatePart[2] = StringRight("0" & $asDatePart[2], 2); make sure the length is 2
        $sTempDate = StringReplace($sTempDate, "d", "@")
        $sTempDate = StringReplace($sTempDate, "m", "#")
        $sTempDate = StringReplace($sTempDate, "y", "&")
        $sTempDate = StringReplace($sTempDate, "@@@@", _DateDayOfWeek($iWday, 0))
        $sTempDate = StringReplace($sTempDate, "@@@", _DateDayOfWeek($iWday, 1))
        $sTempDate = StringReplace($sTempDate, "@@", $asDatePart[3])
        $sTempDate = StringReplace($sTempDate, "@", StringReplace(StringLeft($asDatePart[3], 1), "0", "") & StringRight($asDatePart[3], 1))
        $sTempDate = StringReplace($sTempDate, "####", _DateMonthOfYear($asDatePart[2], 0))
        $sTempDate = StringReplace($sTempDate, "###", _DateMonthOfYear($asDatePart[2], 1))
        $sTempDate = StringReplace($sTempDate, "##", $asDatePart[2])
        $sTempDate = StringReplace($sTempDate, "#", StringReplace(StringLeft($asDatePart[2], 1), "0", "") & StringRight($asDatePart[2], 1))
        $sTempDate = StringReplace($sTempDate, "&&&&", $asDatePart[1])
        $sTempDate = StringReplace($sTempDate, "&&", StringRight($asDatePart[1], 2))
        $sNewDate = $sTempDate
    EndIf
    If $sReg_TimeValue <> "" Then
        $sNewTime = RegRead("HKEY_CURRENT_USER\Control Panel\International", $sReg_TimeValue)
        If $sType = 4 Then
            $sNewTime = StringFormat( "%02d", $asTimePart[1]) & $sNewTime & StringFormat( "%02d", $asTimePart[2])
        ElseIf $sType = 5 Then
            $sNewTime = StringFormat( "%02d", $asTimePart[1]) & $sNewTime & StringFormat( "%02d", $asTimePart[2]) & $sNewTime & StringFormat( "%02d", $asTimePart[3])
        Else
            If $sType <> 0 Then
                If $asTimePart[1] < 12 Then
                    $sNewTime = StringReplace($sNewTime, "tt", "AM")
                    If $asTimePart[1] = 0 Then $asTimePart[1] = 12
                Else
                    $sNewTime = StringReplace($sNewTime, "tt", "PM")
                    If $asTimePart[1] > 12 Then $asTimePart[1] = $asTimePart[1] - 12
                EndIf
            EndIf
            $asTimePart[1] = StringRight("0" & $asTimePart[1], 2); make sure the length is 2
            $asTimePart[2] = StringRight("0" & $asTimePart[2], 2); make sure the length is 2
            $asTimePart[3] = StringRight("0" & $asTimePart[3], 2); make sure the length is 2
            $sNewTime = StringReplace($sNewTime, "hh", StringFormat( "%02d", $asTimePart[1]))
            $sNewTime = StringReplace($sNewTime, "h", StringReplace(StringLeft($asTimePart[1], 1), "0", "") & StringRight($asTimePart[1], 1))
            $sNewTime = StringReplace($sNewTime, "mm", StringFormat( "%02d", $asTimePart[2]))
            $sNewTime = StringReplace($sNewTime, "ss", StringFormat( "%02d", $asTimePart[3]))
        EndIf
        $sNewDate = StringStripWS($sNewDate & " " & $sNewTime, 3)
    EndIf
    Return ($sNewDate)
EndFunc  ;==>_DateTimeFormat
Func _NowTime($sType = 3)
    If $sType < 3 Or $sType > 5 Then $sType = 3
    Return (_DateTimeFormat(@YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC, $sType))
EndFunc  ;==>_NowTime

Share this post


Link to post
Share on other sites

:geek: Another slating and then thanks.

First off I was pointing out the error of your understanding then... I went to have a look through some of my codes to find the solution for you which was actually being helpful, I never said don't open a file I said you can only have 64 files open at once if your gonna insult me at least read what I wrote.

And to your second question...

My script was so long because of the checking of the transfer of the file and the log purging as I was only interested in keeping 100 entries, also it removed jobs after a set period of time after transfer.

It was to get a job from a kiosk and upload the job to another machine, it had all of the retry options because of the limited possible connections into the receiving server and the logging was there to check for failed/successful transfers.

Oh and your welcome :o

the second one was u 2 oh that was a good script man and srry your reply seemed rude so i just sent u a shut up sorry but hell i am just as rude u kno ;)


ƒrankie Paul

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