Jump to content

FileList to Write to a File Help


Recommended Posts

Can anyone show me what I am missing?   I have a folder that pdf files get put in.  The files get processed and moved to a different folder.   Then it is repeated with new pdf files being put in the folder.  What I am trying to do is get the list of files that are currently in the folder before they are moved.   I then write the filelist to a text file.  The script works but only for the first set of files.   The next set or next filelist will not write/append to the current text file. 

#include <file.au3>
#include <Array.au3>
#include <String.au3>
#include <StringConstants.au3>
#include <Date.au3>

$Date = StringFormat("%02u%02u", @MON, @MDAY) & StringRight(@Year, 2)

Local Const $sFilePath = "C:\INCOMING FAXES\*.pdf"
Local $iFileExists = FileExists($sFilePath)
Local $iTimeout = 5

If $iFileExists Then
$selectedfolder = "C:\INCOMING FAXES\"
$aFileList = _FileListToArray($selectedfolder, "*", $FLTA_FILES)
Sleep(2000)

FileOpen("C:\INCOMING FAXES\Faxes Processed Lists\Faxes_Processed_"& $Date &".txt", $FO_APPEND)
Sleep(2000)
_FileWriteFromArray("C:\INCOMING FAXES\Faxes Processed Lists\Faxes_Processed_"& $Date &".txt", $aFileList)

Else
   MsgBox($MB_SYSTEMMODAL, "", "No Faxes at this time " & $iFileExists, $iTimeout)
Exit
EndIF

What am I missing?

Thank you

Link to comment
Share on other sites

Try this code:

#include <File.au3>
#include <Array.au3>
#include <MsgBoxConstants.au3>

Global $Date = StringFormat("%02u%02u", @MON, @MDAY) & StringRight(@YEAR, 2)
Global Const $iTimeout = 5, $FaxFolder = "C:\INCOMING FAXES"
Global Const $iFaxFileDate = $FaxFolder & "\Faxes Processed Lists\Faxes_Processed_" & $Date & ".txt"

If FileExists($FaxFolder & "\*.pdf") Then
    Local $aFileList = _FileListToArray($FaxFolder, "*", $FLTA_FILES)
    Local $hOpen = FileOpen($iFaxFileDate, $FO_APPEND + $FO_OVERWRITE + $FO_CREATEPATH)
    _FileWriteFromArray($hOpen, $aFileList)
    MsgBox($MB_ICONINFORMATION, "", "OK !", $iTimeout)
Else
    MsgBox($MB_ICONINFORMATION, "", "No Faxes at this time !", $iTimeout)
    Exit
EndIf

 

Regards,
 

Link to comment
Share on other sites

Hi xcaliber13,

I see 2 things:

- you do not close the log file with Fileclose(). This could lead to the log file staying opened and so impossible to be written to again until closed.

- there is no loop in your code so it only processes the existing files then stops. You do a while loop so it keeps checking every x seconds:

#include <file.au3>
#include <Array.au3>
#include <String.au3>
#include <StringConstants.au3>
#include <Date.au3>

$Date = StringFormat("%02u%02u", @MON, @MDAY) & StringRight(@Year, 2)

Local Const $sFilePath = "C:\INCOMING FAXES\*.pdf"
Local $iFileExists = FileExists($sFilePath)
Local $iTimeout = 5

$selectedfolder = "C:\INCOMING FAXES\"

FileOpen("C:\INCOMING FAXES\Faxes Processed Lists\Faxes_Processed_"& $Date &".txt", $FO_APPEND)

while 1
    $iFileExists = FileExists($sFilePath)
        If $iFileExists Then
            $aFileList = _FileListToArray($selectedfolder, "*", $FLTA_FILES)
            _FileWriteFromArray("C:\INCOMING FAXES\Faxes Processed Lists\Faxes_Processed_"& $Date &".txt", $aFileList)
        EndIF
    sleep(200)
wend

 

Edited by Neutro
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...