473,395 Members | 1,653 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

how to delete the lines from txt files in vb

how to delete the lines from txt files in vb
Jul 2 '07 #1
2 2573
You'd have to read the text file into VB line by line, write them out line by line & filter out the stuff you don't want.

The new file would be a Temp.Txt file.
The original file would be renamed/deleted & the Temp.Txt file renamed to the original.
Jul 2 '07 #2
Killer42
8,435 Expert 8TB
Note that there are various ways in which you could approach this.

For instance, you could read the entire file into a string array, then write it back out, overwriting the same file and simply skipping lines you don't want. This is a slightly risky technique because as soon as you start writing, you have zapped the original file. If anything goes wrong before you finish, you may have lost your data file.

The safer, and probably more widely-used technique, is to read your input file and write the modified data to a another file - often a temporary file (as SkinHead suggested). Then depending on what you want, you can keep or delete the original file. One common technique used by many applications is to write out a temporary file with some made-up name, then delete the old file, then rename the new file to the original name. There are still things which can go wrong, but the risk, are reduced.
Jul 4 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Srinivasa T.N. | last post by:
Hi, I want to delete the first 3 lines and last 3 lines of a file. How can I do it? I want to repeat on multiple files.. TIA Regards, Seenu.
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
2
by: Hervé Piedvache | last post by:
Hi, A small question ... and your opinions are well done ... I have tested one thing today ... I have a script in charge to insert a lot of files inside one of my db. I have a perl script...
5
by: Magix | last post by:
Hi, This is about File I/O Operation. I want to delete a record from a file, let say FileA. Any one has any good and efficient example/approach? void DeleteRecord(int LineNum) { // open...
3
by: Arpan | last post by:
A Form has a FileUpload, 2 Buttons & a TextBox web server controls. Using the FileUpload control, I want to give users the provision to move & delete files that DO NOT exist in C:\Inetpub\wwwroot...
4
by: Ignoramus6539 | last post by:
There were some strange requests to my server asking for config.php file (which I do not have in the requested location). I did some investigation. Seems to be a virus written in perl,...
2
by: cdun2 | last post by:
Hello, I have some code that reads each line of a text file, and if a line is found where the length of the string in the line is 384, it writes the line to a text file. The other step that I...
24
by: biganthony via AccessMonster.com | last post by:
Hi, I have the following code to select a folder and then delete it. I keep getting a Path/File error on the line that deletes the actual folder. The line before that line deletes the files in...
0
by: Barkingmadscot | last post by:
I am stuck, i cant work out how to remove lines from an array I am loading a text file (a Log) into an array, I know which lines a need, but the logs can be upto 30K sometimes bigger. I found...
2
by: Francesco Pietra | last post by:
Please, how to adapt the following script (to delete blank lines) to delete lines containing a specific word, or words? f=open("output.pdb", "r") for line in f: line=line.rstrip() if line:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.