Solved

Foxpro 7.0 "scan" sub directories

Posted on 2010-11-19
5
649 Views
Last Modified: 2012-05-10
Hi,

I have a directory containing a whole slew of folders. Each of these folders contains several FoxPro databases. What I am trying to do is access a DBF of a certain name in each of the folders. Then sum up a certain field in the dbf, and store it in another table. What I need help with is parsing though each of the directories. Pseudocode might look like this:

For each folder in directory X
      set strD = Directory_name
      use sales.dbf
      Sum amount to X1
      copy strD to table Y
      copy X1 to table Y
Next Folder

Thanks for your help experts.
0
Comment
Question by:FFNOKC
  • 3
  • 2
5 Comments
 
LVL 42

Accepted Solution

by:
pcelba earned 500 total points
ID: 34177512
This is really a short program:

LOCAL lcBaseFolder, lnDirs, laDirs, lnI, lcDir, lnSum

lcBaseFolder = "D:\<YourFolder>\"
lnDirs = ADIR(laDirs, lcBaseFolder + "*.*", "D")

SELECT 0
CREATE TABLE Y (Folder char(100), amount decimal(10,3))
SELECT 0

FOR lnI = 1 TO lnDirs
  IF "D" $ laDirs[lnI, 5]
    lcDir = lcBaseFolder + laDirs[lnI, 1]
    IF FILE(lcDir + "\sales")
      USE (lcDir + "\sales")
      SUM amount TO lnSum
      USE
    ELSE
      lnSum = -1
    ENDIF
    INSERT INTO Y VALUES (lcDir, lnSum)
  ENDIF
NEXT

SELECT Y
GO TOP
BROWSE NOWAIT

Open in new window

0
 

Author Comment

by:FFNOKC
ID: 34191892
pcelba,

When I run this code I get an error saying laDirs is not an array. Does it need to be specifically dimensioned first? I thought VFP automatically created and sized arrays as needed.
0
 
LVL 42

Expert Comment

by:pcelba
ID: 34191942
I supposed it as well...

So, please change the first line to:

LOCAL lcBaseFolder, lnDirs, laDirs[1], lnI, lcDir, lnSum
0
 
LVL 42

Expert Comment

by:pcelba
ID: 34192054
The laDirs can be an array of any dimension, it can even be missing (then private array is created) but it cannot be a single variable prior to the ADIR() function call.

The interesting thing is I don't remember when this error occured in my code in the past...

OTOH, this error message prevents a certain kind of typo bugs in code.
0
 

Author Closing Comment

by:FFNOKC
ID: 34192087
Thanks again. That worked, but it brought me to another question which I will post shortly. :)
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Visual FoxPro (short VFP) is a programming language with it’s own IDE and database, ranking somewhat between Access and VB.NET + SQL Server (Express). Product Description: http://msdn.microsoft.com/en-us/vfoxpro/default.aspx (http://msd…
If you are looking at this article, you have most likely been hit by some version of ransomware and are trying to find out if there is anything you can do, or what way you should react - READ ON!
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question