Search code examples
foxprovisual-foxpro

Import File Daily


I've got a process that needs to run every single day importing files that are pulled down from an FTP site into the same folder. I've got the entire project down and done except for grabbing the files.

Is there any way that I can make FoxPro grab files in a format like this: appointmentlist_METER_05152013.txt appointmentlist_RADIO_05132013.txt

These files are in this folder every morning at 6am, but I need to make sure that I get the METER one for one of the FoxPro programs, and the other one should grab RADIO. The only thing that changes daily is the date in the filename.

If need be I can make sure that each file is pulled into a different folder in the FTP retrieval process, and that each of those folders only contain the file for that day in them.

Any help would be greatly appreciated.

If you need anymore information please feel free to ask.


Solution

  • You can use the ADIR() function to create an array of files on a certain drive and directory.

     SET DEFAULT TO c:\Mydirectory
     MyFilesCount = ADIR(MyArray, '*.TXT')   &&Get all TXT files at this location
    

    You can then loop thru the above array and search for a file containing a certain string using the ATC() function.

     FOR n = 1 TO MyFilesCount
          IF ATC("METER", MyArray[n,1] ) > 0    &&First column contains file name
             ***Run METER process
          ENDIF
          IF ATC("RADIO", MyArray[n,1] ) > 0   &&First column contains file name
             ***Run RADIO process
          ENDIF
     ENDFOR