Solved

Foxpro 7.0 "scan" sub directories

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

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 41

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 41

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
A procedure for exporting installed hotfix details of remote computers using powershell
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

758 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now