Deleting the last charachter of a text file 
Author Message
 Deleting the last charachter of a text file

I have about 200 .txt files which each have a stange character at the very
end of the file which prevents me using them with VB.
Is it possible open each text file, to delete the last character of the text
file and then save it using VB (or anything else if it is possiple).

Thanks
Alex



Fri, 16 Aug 2002 03:00:00 GMT  
 Deleting the last charachter of a text file
That strange character is probably an EOF (Ascii 26) and it shouldn't
prevent VB from using the file.  In what way does VB fail?

In any case, it's this simple (with many variations possible):

fil$ = "SomeFile.Txt"
dim buff as byte()
open fil for binary as 1
redim buff(1 to flen) as byte
get 1,,buff()
close 1
kill fil
open fil for binary as 1
redim preserve buff(1 to flen-1) as byte
put 1,,buff()
close 1

--
     Jim Mack
     MicroDexterity, Inc
     www.microdexterity.com


Quote:
> I have about 200 .txt files which each have a stange character at the very
> end of the file which prevents me using them with VB.
> Is it possible open each text file, to delete the last character of the
text
> file and then save it using VB (or anything else if it is possiple).



Sat, 17 Aug 2002 03:00:00 GMT  
 Deleting the last charachter of a text file
Use the File IO api's as described in the Platform SDK under Base
Services.  It's an easy api and will give you everything you'll ever
need above and beyond vb's intrinsic file handling.  One of the
functions "SetEndOfFile" allows you to truncate the size of a file.
Quote:

> I have about 200 .txt files which each have a stange character at the very
> end of the file which prevents me using them with VB.
> Is it possible open each text file, to delete the last character of the text
> file and then save it using VB (or anything else if it is possiple).

> Thanks
> Alex



Tue, 20 Aug 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Deleting Last Carriage Return from Text File

2. Delete last line of a text file

3. Charachter Count of newly added charachters

4. Deleting the last file

5. Deleted records when text file is linked as table (#deleted)

6. Deleting text from a range in a text file

7. Reading the last few lines only from a text file

8. Rich Text box displaying last inserted text?

9. Update / Delete linked text file data

10. Deleting contents in a text file

11. Deleting contents from a text file

12. delete string from text file

 

 
Powered by phpBB® Forum Software