Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fetching specific .DBF file(s) in a file system - HOW TO? 1

Status
Not open for further replies.

dexterdg

Programmer
Jan 6, 2013
85
PH
Good Day To all!

I'd like to ask for an idea of how to get a specific .dbf file on a file system (with sub folders)

e.g.
[pre]Folder 1
-somefile.dbf
-otherfile.dbf
-Folder 1.1
--thisfile.dbf
--somefile.dbf
Folder 2
-thisfile.dbf
-somefile.dbf
-otherfile.dbf[/pre]

My objective is to Consolidate all "thisfile.dbf" into a dump .dbf for data checking purposes.
Is there already a Thread to that because I dont know the exact terminologies to use.

Thanks,
Dex
 
Are you trying to find all occurences of 'thisfile.dbf' with a file structure?

i.e. open every copy of thisfile.dbf that you can find below c:\somestructure


Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are not good for you.
 
Are they all on the same level? or could they be nested in folders off folders?

i.e.
c:\somestructure\firstlevela\thisfile.dbf
c:\somestructure\firstlevelb\thisfile.dbf
c:\somestructure\firstlevelc\thisfile.dbf
c:\somestructure\firstleveld\thisfile.dbf

or

c:\somestructure\firstlevela\thisfile.dbf
c:\somestructure\firstlevela\secondlevel\thisfile.dbf
c:\somestructure\firstlevela\secondlevel\thirdlevel\thisfile.dbf
c:\somestructure\firstlevelb\thisfile.dbf



Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are not good for you.
 
Yes sir, it is not in the same level.
But its also nice to know how do do it for the same level scenario.

Thanks!
Dex
 
Well, sub folders is a bit trickier.

There is a FAQ for getting all the file names below a given point though - you could modify that
to suit.:

faq184-6312


Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are not good for you.
 
I take it that you want to search part or all of an entire disk drive, looking for all DBFs, and doing something with each of them in turn. Is that correct?

If so, the following code will give you a start. It recursively searches a specified folder and all folder below it, looking for DBFs. For each one it finds, it stores the full path and filename in a cursor.

I have written this in a bit of a hurry and not fully tested it, but it should give you the general idea.

Code:
* Create a cursor to hold the results
CREATE CURSOR csrFiles (FileName M)

LOCAL lcRoot

* Establish the root directory for the search
lcRoot = "c:\SomeStructure"

* Recursively scan the folders, starting at the root,
* looking for the required files.
ScanFolder(lcRoot)

FUNCTION ScanFolder

LPARAMETERS tcFolder

LOCAL lcRoot

LOCAL lcSkeleton, lnFileCount, lcFile, lnI
LOCAL ARRAY laFolder(1)

* Get filenames into an array
lcSkeleton = ADDBS(tcFolder) + "*.*"
lnFileCount = ADIR(laFolder, lcSkeleton, "D")	&& include sub-directories

FOR lnI = 1 TO lnFileCount
  lcFile = LOWER(laFolder(lnI, 1))
  IF lcFile == "." OR lcFile == ".."
* ignore the . and .. entries
    LOOP
  ENDIF

  IF AT("D", laFolder(lnI, 5)) = 0
* Array element is a filename.

* Test for required extension
    IF UPPER(JUSTEXT(laFolder(lnI, 1))) == "DBF"
* Write the filename to the cursor
      INSERT INTO csrFiles VALUES (FORCEPATH(lcFile, tcFolder))
    ENDIF

  ELSE
* Array element is a directory, so recursively scan it
    ScanFolder(ADDBS(tcFolder) + lcFile)
  ENDIF
ENDFOR


Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi
Please do also have a look at
thread184-671709
hth
MK
 
This has enough answers, also referenced in other threads and FAQ.

Still I'd rather ask some questions than giving another answer: How did it come to this situation with numerous locations of the same table? Is there always the same schema of files? I'm not talking of the DBF itself, it obviously would fail to merge data from different schema DBFs, but is it always at the same relative position from some other file? Say from a DBC? Are there DBCs you create in the same manner, all acting as independent databases, eg to separate the data of several mandants? Or separate data of different quarters, years?

If all the same DBFs are part of DBCs, all you need to know is their location - and you obviously need to have that info somewhere in config data. OPEN DATABASE somedb.dbc and it'll know where a certain table is by USE somedb!thistable you get that table of that dbc.

So what do I want to point out? If you're in need to find your data, you're not organised very well. That's not a shame in itself, it happens to all of us, if not in programming, then elsewhere in real life, you're already saying you do this for consolidation. But before you use some search, just think about how do you get at the individual tables now and how you could simply use this mechanism to find a single DBF to find all instances, eg by iterating all storage locations of databases, by iterating all windows accounts, by iterating all installations of the software or whatever the locations are indirectly bound to.

Also at this point: If the locations are per user, you might not have sufficient access to all user profiles local folders, even as admin. So maybe you'd be able to easier consolidate your data by introducing one central database and modify your application to merge data from user specific locations to a central location, or you search the profiles save on a domain controller as server admin.

Just adding these thoughts for the case your easy plan fails could even be easier considering what you know and didn't tell, because you're not aware of how it could help you or your plan fails due to permission restrictions.

Bye, Olaf.
 
Thanks For your wonderful comments/responses!
I have achieved my Goal! Stars for the posts i found helpful.
Thanks again!

P.S.
Sir Olaf,
I didn't develop the program initially, just doing the most out of it.
Yes your observation is correct, yet this file system is what the initials programmers did
for the system policies is not fixed and changes depending on the request/needs.
For flexibility purposes.
Thanks also!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top