?
Solved

Foxpro 7.0 "scan" sub directories

Posted on 2010-11-19
5
Medium Priority
?
656 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 42

Accepted Solution

by:
pcelba earned 2000 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

Linux Academy Android App Now Supports Chromecast

We have some fantastic news for our Android fans. We’re so excited to announce that the Linux Academy Android app is now available with Chromecast support. That’s right – simply download the latest update of the Linux Academy App and start casting your favorite course videos!

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…
In this modest contribution, I want to share with the IT community (especially system administrators, IT Support Engineers and IT Help Desks) about Windows crashes/hangs and how to deal with these particular problems.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month13 days, 4 hours left to enroll

777 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