Jump to content

Delete text from TXT file


DaLiMan
 Share

Recommended Posts

I have a textfile wich I read with a GUI script.

Now I like to have the ability to select and delete the item from the file.

File is like:

line1

line2

line3

Now I know how to select an item, but I can't figure out how to remove it from my textfile.

Please help me for I'm very very stuck on this one..... :idiot:

Link to comment
Share on other sites

@ Doxie

I only want to delete the line I have selected.

The rest must remain intact.

@ Agent Smith

I was also thinking about reading the whole file into the array, delete the line from the array and then paste it back.

But I how can I make the file empty?

Link to comment
Share on other sites

You should simply just read the file into an array, delete the value that you do not want, and then write over the entire file.

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

FileOpen ( "filename", mode )

Parameters

filename Filename of the text file to open.

mode Mode (read or write) to open the file in.

0 = Read mode

1 = Write mode (append to end of file)

2 = Write mode (erase previous contents)

Both write modes will create the file if it does not already exist.

use sparringly though erases all content of .txt file

Edited by Coffee
Link to comment
Share on other sites

K FIRST you read it into an array, there's a UDF for that I think.

THEN you close that connection, open it again in the 2nd mode, write to it with the new values. Very simple I think.

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

Sorry, I've been busy. I thought I could make it in 5 minutes but something came up.

<{POST_SNAPBACK}>

That's OK, thanks anyway.

I'm working on it right now and I think it will work with:

FileRead, StringReplace and _FileCreate.

P.S.: If someone is interested let me know, then I will C&P the code when it works.

P.S.(2):Thanx everybody for all the reply's.

They put me back on the right track. :idiot:

Link to comment
Share on other sites

I regularly add junk senders to my junk senders list in Outlook - a txt file and I used to go in each time to delete everything to the left of and including the '@' sign. I recently wrote this script to do it for me. It may be a useful start for you.

$file=FileOpen(@AppDatadir & "\Microsoft\Outlook\Junk Senders.txt",0)
$file2="C:\My Documents\Backup\Restore\Junk.txt"
While 1
$line=FileReadLine($file)
if @error = -1 then exitloop
$len = StringLen($line)
$pos = StringinStr($line,"@")
$line2 = StringRight($line,$len-$pos)
FileWriteLine($file2,$line2)
wend
FileClose($file)
FileMove(@AppDatadir & "\Microsoft\Outlook\Junk Senders.txt",@AppDatadir & "\Microsoft\Outlook\JunkOld.txt",1)
FileMove("C:\My Documents\Backup\Restore\Junk.txt",@AppDatadir & "\Microsoft\Outlook\Junk Senders.txt")

exit

All the best.

Edited by herworth
[u][font="Arial"]Pete[/font][/u]
Link to comment
Share on other sites

  • 4 years later...

Do you wanna delete the whole content of the file, a line or just a specific word?

I know this is an old post,

Could someone please show me how to delete intire contents of an un-opened text file.

it would sure beat having to start a new post. You see I was looking on here for how to

do it, so I am not lazy, but would like help figuring it out. thanks, I would appricate it.

Edited by program builder
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...