×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

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

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

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

(OP)
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.

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

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

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

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

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

Hi Ilya,

From Hacker's Guide to VFP 7

Quote:



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

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

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

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

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 http://www.vfphelp.com/vfp9/_59k0sp1d8.htm (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
https://www.doschke.name

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

(OP)
Thanks Mike,Ilya,Olaf

I will try your sample codes.

Appreciated very much..

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close