Solved

Foxpro 7.0 "scan" sub directories

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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

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…
After hours on line I found a solution which pointed to the inherited Active Directory permissions . You have to give/allow permissions to the "Exchange trusted subsystem" for the user in the Active Directory...
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Suggested Courses

732 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