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