Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Deleting text files based on content
Message
From
18/10/2011 11:44:59
 
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
01526759
Message ID:
01526775
Views:
36
>>>>>>>How do I delete all text files in c:\texter which have the word KANG in the file contents
>>>>>>>
>>>>>>>Thanks
>>>>>>>
>>>>>>>Colin
>>>>>>
>>>>>>How big are the files? Are they .txt files? Do you want to do this using VFP code?
>>>>>>
>>>>>>If so, loop with adir, filetostr, check the string and then delete.
>>>>>
>>>>>This is my current code which gives me all the files - what does the filetostr line look like and where doe it go?
>>>>>
>>>>>lnFiles = Adir(arrTextFiles1, 'c:\program files\smartserver3\track\*.txt')
>>>>>For ix = 1 To lnFiles
>>>>>
>>>>> Append Blank
>>>>> Append Memo myMails From ('c:\program files\smartserver3\track\'+arrTextFiles1[ix,1])
>>>>>Endfor
>>>>>
>>>>>Thanks
>>>>>
>>>>>Colin
>>>>
>>>>lnFiles = Adir(arrTextFiles1, 'c:\program files\smartserver3\track\*.txt')
>>>>For ix = 1 To lnFiles
>>>>   lcString = filetostr('c:\program files\smartserver3\track\'+arrTextFiles1[ix,1])
>>>>   if 'KANG' $ lcString
>>>>       try 
>>>>          erase ('c:\program files\smartserver3\track\'+arrTextFiles1[ix,1])
>>>>       catch to loError
>>>>             ** process the error
>>>>       endtry 
>>>>       else && assuming we don't want to process these files 
>>>> 
>>>>Append Blank
>>>>Append Memo myMails From ('c:\program files\smartserver3\track\'+arrTextFiles1[ix,1])
>>>>   endif
>>>>Endfor
>>>
>>>Naomi
>>>
>>>You're a star as always
>>>
>>>Many thanks
>>>
>>>Colin
>>
>>Since you already have the file's contents in a variable, you should use
>>Insert into yourdbf (myMails) values (lcString)
Instead of the two Append lines.
>
>Thanks Tore
>
>Naomi's solution has already worked

Yes, I'm gladd you got it working. But using Insert instead of Append is both faster and safer! Append should only be used on cursors, on regular tables SQL commands are normally better.
Previous
Reply
Map
View

Click here to load this message in the networking platform