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!

how to display and append multiple text files with filename and file sizes in the DBF table

Status
Not open for further replies.

keisha1

Programmer
Mar 28, 2019
22
PH
Hi good day, May I beed your help. I have 90 text reports files everyday that I need to manually input the filenames and file size in my worksheet for daily records. can you please give me the sample script commands/functions which I need to put inside command button from vfp to display the filenames, file size and automatically appended in the dbf table once clicked the command button.


Examaple:

COMMAND BUTTON here If you click this, all text filenames and file size
will be displayed and automatically append in recordf.dbf


Display 90 tex files here:
filename file size
repo1.txt 291
repo2.txt 462
repo3.txt 512
repo4.txt 612
repo5.txt 39


Your help is most highly appreciate. Thank you.

 
Something like this:

Code:
CREATE TABLE MyFiles (filename c(32), filesize n(8))
lcDir = "c:\MyDir"  && change this to the name of your directory
lnCount = ADIR(laFiles, FORCEPATH("*.txt", lcDir))
FOR lnI = 1 TO lnCount
  INSERT INTO MyFiles (filename, filesize) VALUES (laFiles(lnI, 1), laFiles(lnI, 2))
ENDFOR

This will create a table (DBF file) with the required information.

The above code would go in the Click event of your command button.

Going one step further, you can copy that to an Excel spreadsheet like this:

Code:
SELECT MyFiles
COPY TO MyExcelFile TYPE XL5

Note that I haven't tested any of the above.

Mike




__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
To Keisha1: Do you need only the listing of those text files, or you also need them to be stored in a table? If it's the latter - as one big text, or each one separately?

To Mike Lewis: I can't recall seeing in VFP's Help this FORCEPATH() function ever, for all my 22 years working with VFP (from v. 3.0b to 9.0 SP2)... Is it something like FORCEEXT(), adds the given path in front of the given file template? And - when it was introduced, in what version?

Regards,

Ilya
 
Hi Ilya,

From Hacker's Guide to VFP 7

AddBS(), DefaultExt(), ForceExt(), ForcePath(), JustDrive(), JustExt(), JustFName(), JustPath(), JustStem()

These functions seem much older than their addition to the language in VFP 6 because they've existed in FoxTools.FLL (and DOS's FPATH.PLB) for a long time. Now they've been integrated into the native language, reducing the need for FoxTools to be loaded. See the FoxTools section, in the File Functions subsection, for details on calling each of the functions.

If you're still working with an older version of FoxPro, you won't miss much by not having these functions. You can load FoxTools, or, if you have access to FoxPro 2.x, you can find many of these functions in code in the GenMenu and GenScrn programs. None of these functions is rocket science; most could be rewritten in an IIF() statement or two.

A word of caution: Since most modern operating systems support long file names, including periods within the file name, you'll want to be careful using these functions. They assume that any characters after the first period are part of the file extension.

Example
? ADDBS("fred") && Returns "fred\"
? DEFAULTEXT("c:\test","txt") && "c:\test.txt"
? DEFAULTEXT("c:\test.doc","txt") && "c:\test.doc"
? DEFAULTEXT("c:\test.document","txt") && "c:\test.document"
? FORCEEXT("c:\test.document","txt") && "c:\test.txt"
? FORCEPATH("c:\test.document","c:\temp")
* returns "C:\Temp\test.document"
? FORCEPATH("c:\test.document","xxx") && "xxx\test.document
? JUSTDRIVE("c:\test.document") && "C:"
? DRIVETYPE(JUSTDRIVE("c:\test.document")) && 3 (see DRIVETYPE)
? JUSTEXT("c:\test.document") && "document"
? JUSTFNAME("c:\test.document") && "test.document"
? JUSTPATH("c:\test.document") && "c:\" - note slash
? JUSTPATH("c:\temp\test.document") && "c:\temp" - no slash
? JUSTPATH("c:\Program Files\test.document")
* "c:\Program Files"
? JUSTSTEM("c:\Program Files\test.document") && "test"

hth

MarK

 
Thank you, Mark!
FoxTools!...
Didn't like to add 3-rd party components unless vitally necessary. FoxTools.FLL, albeit provided, looked also like add-on, so I rarely used it. Same with VFP's class library - any one class I tried, almost never worked the way I needed, so I had to "roll my own"... But that's all in the "rear-view mirror" now.

Regards,

Ilya
 
I started with VFP6, so Foxtools.fll always was with me, but I also didn't notice it before it was mentioned. I don't know if I first asked for a reverse RGB() function and was pointed to RGBCOMP() or if a discussion about advanced trimming between words cam up with REDUCE().

I also don't know if MS introduced it as an example of creating an FLL, it was always part of VFP as far as I know it. The foxtools.chm is very minimalistic and doesn't mention (C) Microsoft in a footer of every topic as the norma dv_foxhelp.chm does. Older versions of Foxpro had a rich Library Construction Kit. The last note in the VFP9 help topic (Library or ActiveX Object Creation) points out MS introduced a Foxpro API that helps you execute VFP code within your FLL or OCX C++ projects. All essential files für such projects are still existing in Home()+"Samples\API", but you need to fiddle with C++ compiler options to work with such legacy libs and even the dependencies of the headers on compilers and Windows made me struggle with this. An old Fox veteran helped me, but that was also over 10 years ago and I while I'm quite sure you can get a project going even in the free current VS.NET community Edition, I'd have to learn that from scratch again anyway. Fox Wiki also only refers on how to set up an empty FLL template project in VS2005.

Back to Foxtools.FLL: There are still some things more about registry and clipboard, but most of it is outdated and as nice as it is, that it would be a simpler interface than Windows API declares and structs and struggling with the OS changes like UAC, you need the Windows API to do some things nowadays.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Thanks Mike,Ilya,Olaf

I will try your sample codes.

Appreciated very much..

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top