0

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.

Lordv8r
  • 90
  • 1
  • 2
  • 9

2 Answers2

2

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
Jerry
  • 6,357
  • 8
  • 35
  • 50
  • Sorry I'm pretty new to FoxPro, is there a table or cursor that these file names will be populated in? – Lordv8r May 16 '13 at 20:13
  • 1
    ADIR() populates an array with the specified files. – Tamar E. Granor May 16 '13 at 20:59
  • Can I get something like JUSTFNAME() from that array? I'm trying to append from a file whose filename should be contained in that array. Thank you all for your help. – Lordv8r May 16 '13 at 21:35
  • 1
    @Lordv8r, ADIR() puts things in a multi-dimension array. [x,1] is the file name (less the path). That is why Jerry is testing via ATC() which is look for the given string ex: "METER" REGARDLESS OF upper/lower case. If found in the file name, do the "Meter" process. – DRapp May 17 '13 at 11:13
  • Thank you all for the help I did go with this array and it works perfect. Thanks for helping me understand it. – Lordv8r May 22 '13 at 16:23
0
m.CDATE = Transform(Day(Date()), '@L 99') + Transform(Month(Date()), '@L 99') + Transform(Year(Date()), '@L 9999')

m.CFILE = 'C:\SOMEFOLDER\appointmentlist_RADIO_' + M.CDATE + '.txt'

If File(M.CFILE) Then
    Do RADIOPROCESS With m.CFILE
Endif

m.CFILE = 'C:\SOMEFOLDER\appointmentlist_METER_' + M.CDATE + '.txt'

If File(M.CFILE) Then
    Do METERPROCESS With m.CFILE
Endif
Carlos Alloatti
  • 193
  • 2
  • 9