Jump to content
Sign in to follow this  
Santana

File Manipulation Problem

Recommended Posts

Santana

Hi all,

I thought I had this solved but still there is a problem with the code.I have 7 files that are supposed to be in a directory at some point in time. if the files are there, they are all processed (got that)

if one or more files are missing, I want to process ONLY the missing files.I have an array with all the file names that calls a function to process the files and deletes the name from the array as it process them and at the end if the array is not empty (meaning that there are missing files). then I call another function that check if the processed file exists in another directory. If the file doesnt exists then it is supposed to run only the missing files.

I want to exit the script once all the files are captured or when it has tried about 20 times (I am thinking to set the timer to have the script try for about 1 1/2 hour then send an alert).

My issue is really silly: I tried renaming the files (to simulate missign files) and rename them back while the script was looping. the script does process them but never exit.

Can some one give me suggestions on how to go about this?

Thanks in advance.

$RootFolder = '\\Macenmedews\'
$sJulDate = _DateToDayValue (@YEAR, @MON, @MDAY)
Dim $Y, $M, $D
$sJulDate = _DayValueToDate ($sJulDate, $Y, $M, $D)  ; need to change to prior date
$sJulDate = StringReplace($sJulDate, "/", "")
$old = $RootFolder & 'MedeFinance\OP@XFER#_' & $sJulDate & '.txt'
$file = FileOpen($old , 0)
Dim $aArray[8]
$aArray[1]="TRAN@AUD_" & $sJulDate
$aArray[2]="ALPHA@DI_" & $sJulDate
$aArray[3]="ALPHA@IN_" & $sJulDate
$aArray[4]="IP@XFER#_" & $sJulDate
$aArray[5]="OP@EXCEP_" & $sJulDate
$aArray[6]="BILLSUMC_" & $sJulDate
$aArray[7]="OP@XFER#_" & $sJulDate
for $a = 0 to UBound($aArray)-1
if FileExists($RootFolder & "\PFSrpts\" & $aArray[0] ) = 1 Then
if stringlen($aArray[0]) < 1 then
_ArrayDelete($aArray, 0)
else
fileprocess($aArray[0])
$arraysize = UBound($aArray)
sleep(10)
_ArrayDelete($aArray, 0)
endif
Else
_ArrayAdd($aArray, $aArray[0])
_ArrayDelete($aArray, 0)
endif
NEXT
RepeatFun()

func RepeatFun()
$n = 1
while 1
    if $n = 20 then exit
sleep(5000)
    if FileExists($RootFolder & 'MedeFinance\' & "TRAN@AUD_" & $sJulDate & '.txt') = 0 then fileprocess("TRAN@AUD_" & $sJulDate)
    if FileExists($RootFolder & 'MedeFinance\' & "ALPHA@DI_" & $sJulDate & '.txt') = 0 then fileprocess("ALPHA@DI_" & $sJulDate)
    if FileExists($RootFolder & 'MedeFinance\' & "ALPHA@IN_" & $sJulDate & '.txt') = 0 then fileprocess("ALPHA@IN_" & $sJulDate)
    if FileExists($RootFolder & 'MedeFinance\' & "IP@XFER#_" & $sJulDate & '.txt') = 0 then fileprocess("IP@XFER#_" & $sJulDate)
    if FileExists($RootFolder & 'MedeFinance\' & "OP@EXCEP_" & $sJulDate & '.csv') = 0 then fileprocess("OP@EXCEP_" & $sJulDate)
    if FileExists($RootFolder & 'MedeFinance\' & "BILLSUMC_" & $sJulDate & '.csv') = 0 then fileprocess("BILLSUMC_" & $sJulDate)
    if FileExists($RootFolder & 'MedeFinance\' & "OP@XFER#_" & $sJulDate & '.txt') = 0 then fileprocess("OP@XFER#_" & $sJulDate)
    $n +=1
WEnd
EndFunc

func fileprocess($xfiles)
$file = $xfiles
ConsoleWrite('file is '& $file & @cr)
$Call = "Monarch /rpt:"
$RptLoc = '"' & $file &  '"'
$mod = ''
$export = ''
select
case $file = "ALPHA@DI_" & $sJulDate
$mod = " /mod:" & '"'  & $RootFolder & "\MonarchExe\Mod\67_AlphaDi_Account_Level_April_15.mod" & '"'
$export = " /Exp:" & $RootFolder & "MedeFinance\" & $file & ".txt"
case $file = "ALPHA@IN_" & $sJulDate
$mod = " /mod:" & '"'  & $RootFolder & "\MonarchExe\Mod\67_AlphaIn_Account_Level_April_15.mod" & '"'
$export = " /Exp:" & $RootFolder & "MedeFinance\" & $file  & ".txt"
case $file = "OP@EXCEP_" & $sJulDate
$mod = " /mod:" & '"'  & $RootFolder & "MonarchExe\Mod\OP-Exception.xmod" & '"'
$export = " /Exp:" & $RootFolder & "MedeFinance\" & $file & ".csv"
case $file = "BILLSUMC_" & $sJulDate
$mod = " /mod:" & '"'  & $RootFolder & "\MonarchExe\Mod\BILLSUMC_WSummary.xmod" & '"'
$export = " /Exp:" & $RootFolder & "MedeFinance\" & $file & ".csv"
case $file= "TRAN@AUD_" & $sJulDate
$mod = " /mod:" & '"'  & $RootFolder & "\MonarchExe\Mod\TRANAUD_DETAILED.mod" & '"'
$export = " /Exp:" & $RootFolder & "MedeFinance\" & $file & ".txt"
case $file = "IP@XFER#_" & $sJulDate
$mod = " /mod:" & '"'  & $RootFolder & "\MonarchExe\Mod\ms_ipxfer.xmod" & '"' & ' "/S"'
$export = " /Exp:" & $RootFolder & "MedeFinance\" & $file & ".txt"
case $file = "OP@XFER#_" & $sJulDate
$mod = " /mod:" & '"'  & $RootFolder & "\MonarchExe\Mod\ms_opxfer.xmod" & '"' & ' "/S"'
$export = " /Exp:" & $RootFolder & "MedeFinance\" & $file  & ".txt"
Case Else
EndSelect
$rpt = $file
$fileLocation = $RootFolder & 'PFSrpts\' & $file
$rpt = $Call & $fileLocation & $mod & $export
$objshell = objcreate("wscript.shell")
$objshell.Run($rpt)
ProcessWaitClose("Monarch.exe")
Sleep(50)
EndFunc

Just another special date with a different challenge

Share this post


Link to post
Share on other sites
Scriptonize

When you change the function into....

func RepeatFun()
$n = 1
while $n < 20
    sleep(5000)
    if FileExists($RootFolder & 'MedeFinance\' & "TRAN@AUD_" & $sJulDate & '.txt') = 0 then fileprocess("TRAN@AUD_" & $sJulDate)
    if FileExists($RootFolder & 'MedeFinance\' & "ALPHA@DI_" & $sJulDate & '.txt') = 0 then fileprocess("ALPHA@DI_" & $sJulDate)
    if FileExists($RootFolder & 'MedeFinance\' & "ALPHA@IN_" & $sJulDate & '.txt') = 0 then fileprocess("ALPHA@IN_" & $sJulDate)
    if FileExists($RootFolder & 'MedeFinance\' & "IP@XFER#_" & $sJulDate & '.txt') = 0 then fileprocess("IP@XFER#_" & $sJulDate)
    if FileExists($RootFolder & 'MedeFinance\' & "OP@EXCEP_" & $sJulDate & '.csv') = 0 then fileprocess("OP@EXCEP_" & $sJulDate)
    if FileExists($RootFolder & 'MedeFinance\' & "BILLSUMC_" & $sJulDate & '.csv') = 0 then fileprocess("BILLSUMC_" & $sJulDate)
    if FileExists($RootFolder & 'MedeFinance\' & "OP@XFER#_" & $sJulDate & '.txt') = 0 then fileprocess("OP@XFER#_" & $sJulDate)
    $n = $n + 1
WEnd
EndFunc

does it then run as it should run?


If you learn from It, it's not a mistake

Share this post


Link to post
Share on other sites
Santana

I haven't try the While loop yet. it was supposed to be commented.

I think I uncomented the lines after I posted the question.

Edited by Santana

Just another special date with a different challenge

Share this post


Link to post
Share on other sites
Scriptonize

Ah, I see,

you need to add an exit statement behind:

......your code

NEXT

RepeatFun()

EXIT

func RepeatFun()

......your code....


If you learn from It, it's not a mistake

Share this post


Link to post
Share on other sites
Santana

I had this before but didnt work

while 1
  if FileExists($RootFolder & 'MedeFinance\' & "TRAN@AUD_" & $sJulDate & '.txt') = 0 then fileprocess("TRAN@AUD_" & $sJulDate)
    if FileExists($RootFolder & 'MedeFinance\' & "ALPHA@DI_" & $sJulDate & '.txt') = 0 then fileprocess("ALPHA@DI_" & $sJulDate)
    if FileExists($RootFolder & 'MedeFinance\' & "ALPHA@IN_" & $sJulDate & '.txt') = 0 then fileprocess("ALPHA@IN_" & $sJulDate)
    if FileExists($RootFolder & 'MedeFinance\' & "IP@XFER#_" & $sJulDate & '.txt') = 0 then fileprocess("IP@XFER#_" & $sJulDate)
    if FileExists($RootFolder & 'MedeFinance\' & "OP@EXCEP_" & $sJulDate & '.csv') = 0 then fileprocess("OP@EXCEP_" & $sJulDate)
    if FileExists($RootFolder & 'MedeFinance\' & "BILLSUMC_" & $sJulDate & '.csv') = 0 then fileprocess("BILLSUMC_" & $sJulDate)
    if FileExists($RootFolder & 'MedeFinance\' & "OP@XFER#_" & $sJulDate & '.txt') = 0 then fileprocess("OP@XFER#_" & $sJulDate)

WEnd
Edited by Santana

Just another special date with a different challenge

Share this post


Link to post
Share on other sites
Scriptonize

$RootFolder = '\\Macenmedews\'
$sJulDate = _DateToDayValue (@YEAR, @MON, @MDAY)
Dim $Y, $M, $D
$sJulDate = _DayValueToDate ($sJulDate, $Y, $M, $D)  ; need to change to prior date
$sJulDate = StringReplace($sJulDate, "/", "")
$old = $RootFolder & 'MedeFinance\OP@XFER#_' & $sJulDate & '.txt'
$file = FileOpen($old , 0)
Dim $aArray[8]
$aArray[1]="TRAN@AUD_" & $sJulDate
$aArray[2]="ALPHA@DI_" & $sJulDate
$aArray[3]="ALPHA@IN_" & $sJulDate
$aArray[4]="IP@XFER#_" & $sJulDate
$aArray[5]="OP@EXCEP_" & $sJulDate
$aArray[6]="BILLSUMC_" & $sJulDate
$aArray[7]="OP@XFER#_" & $sJulDate
for $a = 0 to UBound($aArray)-1
if FileExists($RootFolder & "\PFSrpts\" & $aArray[0] ) = 1 Then
if stringlen($aArray[0]) < 1 then
_ArrayDelete($aArray, 0)
else
fileprocess($aArray[0])
$arraysize = UBound($aArray)
sleep(10)
_ArrayDelete($aArray, 0)
endif
Else
_ArrayAdd($aArray, $aArray[0])
_ArrayDelete($aArray, 0)
endif
NEXT
RepeatFun()
;---------------------------------------Here--------------------------------
EXIT
;---------------------------------------------------------------------------
func RepeatFun()
$n = 1
while 1
    if $n = 20 then exit
sleep(5000)
    if FileExists($RootFolder & 'MedeFinance\' & "TRAN@AUD_" & $sJulDate & '.txt') = 0 then fileprocess("TRAN@AUD_" & $sJulDate)
    if FileExists($RootFolder & 'MedeFinance\' & "ALPHA@DI_" & $sJulDate & '.txt') = 0 then fileprocess("ALPHA@DI_" & $sJulDate)
    if FileExists($RootFolder & 'MedeFinance\' & "ALPHA@IN_" & $sJulDate & '.txt') = 0 then fileprocess("ALPHA@IN_" & $sJulDate)
    if FileExists($RootFolder & 'MedeFinance\' & "IP@XFER#_" & $sJulDate & '.txt') = 0 then fileprocess("IP@XFER#_" & $sJulDate)
    if FileExists($RootFolder & 'MedeFinance\' & "OP@EXCEP_" & $sJulDate & '.csv') = 0 then fileprocess("OP@EXCEP_" & $sJulDate)
    if FileExists($RootFolder & 'MedeFinance\' & "BILLSUMC_" & $sJulDate & '.csv') = 0 then fileprocess("BILLSUMC_" & $sJulDate)
    if FileExists($RootFolder & 'MedeFinance\' & "OP@XFER#_" & $sJulDate & '.txt') = 0 then fileprocess("OP@XFER#_" & $sJulDate)
    $n +=1
WEnd
EndFunc

func fileprocess($xfiles)
$file = $xfiles
ConsoleWrite('file is '& $file & @cr)
$Call = "Monarch /rpt:"
$RptLoc = '"' & $file &  '"'
$mod = ''
$export = ''
select
case $file = "ALPHA@DI_" & $sJulDate
$mod = " /mod:" & '"'  & $RootFolder & "\MonarchExe\Mod\67_AlphaDi_Account_Level_April_15.mod" & '"'
$export = " /Exp:" & $RootFolder & "MedeFinance\" & $file & ".txt"
case $file = "ALPHA@IN_" & $sJulDate
$mod = " /mod:" & '"'  & $RootFolder & "\MonarchExe\Mod\67_AlphaIn_Account_Level_April_15.mod" & '"'
$export = " /Exp:" & $RootFolder & "MedeFinance\" & $file  & ".txt"
case $file = "OP@EXCEP_" & $sJulDate
$mod = " /mod:" & '"'  & $RootFolder & "MonarchExe\Mod\OP-Exception.xmod" & '"'
$export = " /Exp:" & $RootFolder & "MedeFinance\" & $file & ".csv"
case $file = "BILLSUMC_" & $sJulDate
$mod = " /mod:" & '"'  & $RootFolder & "\MonarchExe\Mod\BILLSUMC_WSummary.xmod" & '"'
$export = " /Exp:" & $RootFolder & "MedeFinance\" & $file & ".csv"
case $file= "TRAN@AUD_" & $sJulDate
$mod = " /mod:" & '"'  & $RootFolder & "\MonarchExe\Mod\TRANAUD_DETAILED.mod" & '"'
$export = " /Exp:" & $RootFolder & "MedeFinance\" & $file & ".txt"
case $file = "IP@XFER#_" & $sJulDate
$mod = " /mod:" & '"'  & $RootFolder & "\MonarchExe\Mod\ms_ipxfer.xmod" & '"' & ' "/S"'
$export = " /Exp:" & $RootFolder & "MedeFinance\" & $file & ".txt"
case $file = "OP@XFER#_" & $sJulDate
$mod = " /mod:" & '"'  & $RootFolder & "\MonarchExe\Mod\ms_opxfer.xmod" & '"' & ' "/S"'
$export = " /Exp:" & $RootFolder & "MedeFinance\" & $file  & ".txt"
Case Else
EndSelect
$rpt = $file
$fileLocation = $RootFolder & 'PFSrpts\' & $file
$rpt = $Call & $fileLocation & $mod & $export
$objshell = objcreate("wscript.shell")
$objshell.Run($rpt)
ProcessWaitClose("Monarch.exe")
Sleep(50)
EndFunc


If you learn from It, it's not a mistake

Share this post


Link to post
Share on other sites
JSThePatriot

He needs to fix his function. It never exits the loop until it has completed all 20 iterations. Also if he wanted a specific number of iterations a For Loop is usually better. Below is how I would handle it.

Func RepeatFun()
    Local $blnProcessed[7]

    For n = 1 To 20 Step 1
        Sleep(5000)
        If FileExists($RootFolder & 'MedeFinance\' & "TRAN@AUD_" & $sJulDate & '.txt') = 0 Then
            fileprocess("TRAN@AUD_" & $sJulDate)
            $blnProcessed[0] = true
        EndIf
        If FileExists($RootFolder & 'MedeFinance\' & "ALPHA@DI_" & $sJulDate & '.txt') = 0 Then
            fileprocess("ALPHA@DI_" & $sJulDate)
            $blnProcessed[1] = true
        EndIf
        If FileExists($RootFolder & 'MedeFinance\' & "ALPHA@IN_" & $sJulDate & '.txt') = 0 Then
            fileprocess("ALPHA@IN_" & $sJulDate)
            $blnProcessed[2] = true
        EndIf
        If FileExists($RootFolder & 'MedeFinance\' & "IP@XFER#_" & $sJulDate & '.txt') = 0 Then
            fileprocess("IP@XFER#_" & $sJulDate)
            $blnProcessed[3] = true
        EndIf
        If FileExists($RootFolder & 'MedeFinance\' & "OP@EXCEP_" & $sJulDate & '.csv') = 0 Then
            fileprocess("OP@EXCEP_" & $sJulDate)
            $blnProcessed[4] = true
        EndIf
        If FileExists($RootFolder & 'MedeFinance\' & "BILLSUMC_" & $sJulDate & '.csv') = 0 Then
            fileprocess("BILLSUMC_" & $sJulDate)
            $blnProcessed[5] = true
        EndIf
        If FileExists($RootFolder & 'MedeFinance\' & "OP@XFER#_" & $sJulDate & '.txt') = 0 Then
            fileprocess("OP@XFER#_" & $sJulDate)
            $blnProcessed[6] = true
        EndIf

        If $blnProcessed[0] AND $blnProcessed[1] AND $blnProcessed[2] AND $blnProcessed[3] AND $blnProcessed[4] AND $blnProcessed[5] AND $blnProcessed[6] Then
            ;All have been processed...
            ExitLoop
        EndIf
    Next
EndFunc

I hope this makes sense. This will exit the loop as soon as all of them are processed. You can optionally leave in the Exit call as Scriptonize has suggested, but it's not required to put an "Exit" call in your script for it to know it's at the end of the script.

Edit01: You could also make your FileProcess() return a true false value if it's been processed so you wouldn't need the extra line you could still do it all in one statement... as follows

If FileExists($RootFolder & 'MedeFinance\' & "OP@XFER#_" & $sJulDate & '.txt') = 0 Then $blnProcessed[6] = fileprocess("OP@XFER#_" & $sJulDate)

I hope I have helped some,

Jarvis

Edited by JSThePatriot

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Share this post


Link to post
Share on other sites
Santana

Thanks alot Js,

I trieds and it did exit this time. I will play with your last suggestion tomorrow. Thanks

again for all the inputs.


Just another special date with a different challenge

Share this post


Link to post
Share on other sites
JSThePatriot

Santana,

Glad I could be of assistance. Keep up the good work. Keep in mind to get the colors like I have in my code to use the [autoit ] [ /autoit] tags (no spaces).

Good Luck,

Jarvis


AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Share this post


Link to post
Share on other sites
Santana

i Jarvis,

I tried the script today and don't know if I'm not understanding the function well.

The if statements in the function return true (only if a file is not in the specified directory)while at the end of the function there's an if statement (the one that exit the loop). that checks if all values in the array

$blnProcessed[] are true. If I'm understanding correctly, some values may not be true because the files already in exist and don't need to be re-processed. In that case the loop will continue even if all the files are where I need them to be. When I tried today , I noticed that the loop never exits until it runs completly.

Any Idea?


Just another special date with a different challenge

Share this post


Link to post
Share on other sites
JSThePatriot

i Jarvis,

I tried the script today and don't know if I'm not understanding the function well.

The if statements in the function return true (only if a file is not in the specified directory)while at the end of the function there's an if statement (the one that exit the loop). that checks if all values in the array

$blnProcessed[] are true. If I'm understanding correctly, some values may not be true because the files already in exist and don't need to be re-processed. In that case the loop will continue even if all the files are where I need them to be. When I tried today , I noticed that the loop never exits until it runs completly.

Any Idea?

Yea, I totally missed that the files were only being processed if they DIDN'T exist. My bad... I have modified the function below:
Func RepeatFun()
    Local $blnProcessed[7] = [False, False, False, False, False, False, False]

    For n = 1 To 20 Step 1
        Sleep(5000)
        If FileExists($RootFolder & 'MedeFinance\' & "TRAN@AUD_" & $sJulDate & '.txt') Then
            $blnProcessed[0] = True
        Else
            fileprocess("TRAN@AUD_" & $sJulDate)
            $blnProcessed[0] = True
        EndIf
        If FileExists($RootFolder & 'MedeFinance\' & "ALPHA@DI_" & $sJulDate & '.txt') Then
            $blnProcessed[1] = True
        Else
            fileprocess("ALPHA@DI_" & $sJulDate)
            $blnProcessed[1] = True
        EndIf
        If FileExists($RootFolder & 'MedeFinance\' & "ALPHA@IN_" & $sJulDate & '.txt') Then
            $blnProcessed[2] = True
        Else
            fileprocess("ALPHA@IN_" & $sJulDate)
            $blnProcessed[2] = True
        EndIf
        If FileExists($RootFolder & 'MedeFinance\' & "IP@XFER#_" & $sJulDate & '.txt') Then
            $blnProcessed[3] = True
        Else
            fileprocess("IP@XFER#_" & $sJulDate)
            $blnProcessed[3] = True
        EndIf
        If FileExists($RootFolder & 'MedeFinance\' & "OP@EXCEP_" & $sJulDate & '.csv') Then
            $blnProcessed[4] = True
        Else
            fileprocess("OP@EXCEP_" & $sJulDate)
            $blnProcessed[4] = True
        EndIf
        If FileExists($RootFolder & 'MedeFinance\' & "BILLSUMC_" & $sJulDate & '.csv') Then
            $blnProcessed[5] = True
        Else
            fileprocess("BILLSUMC_" & $sJulDate)
            $blnProcessed[5] = True
        EndIf
        If FileExists($RootFolder & 'MedeFinance\' & "OP@XFER#_" & $sJulDate & '.txt') Then
            $blnProcessed[6] = True
        Else
            fileprocess("OP@XFER#_" & $sJulDate)
            $blnProcessed[6] = True
        EndIf

        If $blnProcessed[0] AND $blnProcessed[1] AND $blnProcessed[2] AND $blnProcessed[3] AND $blnProcessed[4] AND $blnProcessed[5] AND $blnProcessed[6] Then
            ;All have been processed...
            ExitLoop
        EndIf
    Next
EndFunc

Let me know if that does it for you,

Jarvis


AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

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  

×