Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Reading in an ascii file with FOPEN()
Message
 
To
04/03/1999 23:08:28
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00194312
Message ID:
00196799
Views:
31
>I need to read in a ascii file and do a string search on each line and
>denpending on what is found with the string search, I will write out to another ascii file. The form will be:
>open first ascii file
>open second ascii file
>do while .t.
> read in a line of the first ascii
> if search criteria is met
> write out a line to the second ascii file
> else
> loop
>endif
>endo
>
>I will then do a APPEND FROM to bring the second ascii file into a vfp dbf. Any ideas?

I do something similar - but instead of writing from one text file to another, then importing I read the first text file, analyze each line, and write the data directly into my tables.

My example does two sets of low-level file reads. The first analyses the files listed by a DIR type command (actually, Novell's NDIR) and the second opens old files to determine what version WP files they are, so I know where to extract the file properties from within the file (descriptive file name, etc).

When a file is deleted, the data extracted from it goes into my table, so I have a better chance of finding files after they are archived. I've tried to Bold the lines that are most important to you.

Here's some code:

USE f:\apps\archiver\deleted.dbf IN 0 SHARED
SCATTER MEMVAR MEMO BLANK
DIMENSION delimiter(7)
* Documents are deleted only after 1 year of inactivity!

OLD_DATE=365

RDSize=1000
OldCount=0
OrphanCount=0
TempCount=0
m.EXT=""
m.directory="F:\PROJECTS\"
* Build the file spec to look for...

SET DEFAULT TO F:\PROJECTS

befdate = date()-old_date
* path=ALLTRIM(path)
* file_spec = IIF(RIGHT(path,1)="\",path,path+"\")+ALLTRIM(file_spec)
file_spec = "F:\PROJECTS\*.*"
* List a directory to a temporary text file
WAIT WINDOW "Listing the directory.... Please wait" NOWAIT

temp_name=SYS(3)+".DIR"

RUN NDIR &file_spec /D /FO /S > &Temp_Name

SELECT deleted

* Scan the directory listing and fill the output table
test4wp = CHR(255) + "WPC"
test4old = CHR(1) + CHR(10) + CHR(0)
test4start = REPLICATE(CHR(32),10) + CHR(0)
test4new = CHR(1) + CHR(10) + CHR(2)
mHandle1=FOPEN(temp_name)
DO Init_Thermometer
rdsize=10000
DO WHILE ! FEOF(mHandle1)
curr_line=ALLTRIM(FGETS(mHandle1))
DO CASE
CASE AT("\*.",Curr_Line)>0 && It's the path line
StartLoc=RAT(":",Curr_Line)+1
SubLen=RAT("\",Curr_Line)-StartLoc+1
m.Directory="\"+SUBSTR(Curr_Line, StartLoc, SubLen) && Path ending with \
CASE Left(Curr_Line,4)="DOS:" && It's the filename
m.Extension=RIGHT(Curr_Line,3) && File Extension
StartLoc=7
SubLen=RAT(".",Curr_Line)-StartLoc
m.Name=ALLTRIM(SUBSTR(Curr_Line,StartLoc,SubLen)) && File Name
CASE Left(Curr_Line,5)="OS/2:" && It's the LONG filename
StartLoc=7
SubLen=RAT(".",Curr_Line)-StartLoc
m.OS_Name=ALLTRIM(SUBSTR(Curr_Line,StartLoc,SubLen)) && Long File Name
CASE LEFT(Curr_Line,6)="Owner:" && File Owner
StartLoc=RAT(":",Curr_Line)+1
SubLen=Len(Curr_Line)-StartLoc+1
m.Owner=ALLTRIM(SUBSTR(Curr_Line,StartLoc,SubLen))
CASE "Last update:" $ Curr_Line && Last Update
m.Last_Rev = CTOD(SubStr(Curr_Line,AT("/",Curr_Line)-2,8))
CASE "Last accessed:" $ Curr_Line && Last Update
m.LastAccess= CTOD(SubStr(Curr_Line,AT("/",Curr_Line)-2,8))
CASE "Created/Copied:" $ Curr_Line && Last Update
m.Created = CTOD(SubStr(Curr_Line,AT("/",Curr_Line)-2,8))
CASE "File size:" $ Curr_Line && End of Record - process it!

IF (m.last_rev < befdate) && It's Old!
m.DelDate = DATE()
m.Archived = .T.
FullPath = "F:" + m.Directory + m.Name + "." + m.Extension
* date is before today minus ageing
IF ("\WP\" $ Fullpath)
* It is in a WP path, so check to see if it's a WP file
wp_file=FOPEN(Fullpath)
=FSEEK(wp_file, 0) && Move pointer to BOF
l_string = FREAD(wp_file, rdsize) && Read first thousand bytes
DO CASE
CASE LEFT(l_string, 4) = Test4WP .AND. SUBSTR(l_string, 9, 3) = test4old && It's WP 5.0 or earlier
WAIT WINDOW "We have an early file" NOWAIT
temp = AT(test4start,l_string)
l_string = SUBSTR(l_string, temp, rdsize-temp)
FOR COUNT=1 TO ALEN(delimiter)
delimiter(COUNT)=AT(CHR(0),l_string,COUNT)
ENDFOR
m.longname = ALLTRIM(SUBSTR(l_string,delimiter(1)+1,delimiter(1)+69))
m.filetype = ALLTRIM(SUBSTR(l_string,delimiter(1)+69,delimiter(2)-delimiter(1)-69))
m.subject = ALLTRIM(SUBSTR(l_string,delimiter(2)+1,delimiter(3)-delimiter(2)-1))
m.author = ALLTRIM(SUBSTR(l_string,delimiter(3)+1,delimiter(4)-delimiter(3)-1))
m.typist = ALLTRIM(SUBSTR(l_string,delimiter(4)+1,delimiter(5)-delimiter(4)-1))
m.account = ALLTRIM(SUBSTR(l_string,delimiter(6)+1,delimiter(7)-delimiter(6)-1))
CASE LEFT(l_string, 4) = Test4WP .AND. SUBSTR(l_string, 9, 3) = test4new && It's WP 6.0 or later
WAIT WINDOW "We have a modern file" NOWAIT
* We need to extract values from new file format
m.longname = CleanString(CHR(17))
m.filetype = CleanString(CHR(18))
m.subject = CleanString(CHR(46))
m.author = CleanString(CHR(5))
m.typist = CleanString(CHR(48))
m.account = CleanString(CHR(2))
ENDCASE
=FCLOSE(wp_file)
ENDIF
APPEND BLANK
GATHER MEMVAR MEMO
WAIT WINDOW "We would have erased " + FullPath NOWAIT
ERASE &FullPath
SCATTER MEMVAR MEMO BLANK
ENDIF
ENDCASE
DO Update_Thermometer
ENDDO

=FCLOSE(mHandle1)
ERASE &temp_name

WAIT WINDOW CHR(7)+"The file Deleted.DBF now contains a listing of all deleted files." TIMEOUT 5
Kogo Michael Hogan

"Pinky, are you pondering what I'm pondering?"
I think so Brain, but "Snowball for Windows"?

Ideate Web Site
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform