Solved

Foxpro 7.0 "scan" sub directories

Posted on 2010-11-19
5
652 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 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

Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

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…
Article by: Justin
In light of the WannaCry ransomware attack that affected millions of Windows machines, you might wonder if your Mac needs protecting. Yes, it does and here is how to do it.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

729 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