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!

*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.

Jobs

Utility Program

Extract Files from General Fields by baltman
Posted: 18 Jul 04 (Edited 20 Jul 04)

There are only a couple of tricks to extracting files out of general fields. First you have to isolate just one file into it's own .FPT file, and secondly you have to strip the correct number of characters off the start of the resulting file before you write out the stored file.

Even files with the same extension can have vastly different headers, so this code is definitely not one-size fits all and will work best when all or most of the files were created consistiently so that the header matches the sample file.

I suppose someone could build a library of 'starter strings' and/or how VFP handles loading/storing each one.

I also noticed that while the program works with Excel files too, the extracted file opens into Excel as hidden and needs to be unhidden. Weird huh?

This code assumes you have a filename without a path stored in the dbf... if you don't have this situation you can always make one by adding a character field and populating it with transform(recno()).

Anyway, just copy and paste this code into a prg and run.

CODE

CLOSE ALL
lcSafe=SET("safe")
SET safe off
messagebox("Please select the table you want to extract files from.")
lcTargetTable=FULLPATH(GETFILE([dbf]))

lcFilename = INPUTBOX("Type in the name of the field with your file names.")
lcGeneralFieldname = INPUTBOX("Type in the name of the general field.")

messagebox("Please select an example of the file type you want to extract e.g. a Word file")
lcTestStr=LEFT(FILETOSTR(GETFILE()),10)

SET DEFAULT TO JUSTPATH(lcTargetTable)

USE (lcTargetTable)
SCAN
    lcOutputNameAndPath=SYS(5)+SYS(2003)+[\]+&lcFilename
    COPY FIELD (lcGeneralFieldname),&lcFilename TO MyTempFile NEXT 1
    lcFile=FILETOSTR("MyTempFile.FPT")
    lcFile=RIGHT(lcFile,LEN(lcFile)-(ATC(lcTestStr,lcFile)-1))
    IF ATC(lcTestStr,lcFile)<1000 &&otherwise assume it's a different file type
        STRTOFILE(lcFile,lcOutputNameAndPath)
    ENDIF
ENDSCAN

DROP TABLE MyTempFile
SET SAFETY &lcSafe

Please let me know if this helps
Brian

Back to Microsoft: Visual FoxPro FAQ Index
Back to Microsoft: Visual FoxPro Forum

My Archive

Resources

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