DaLiMan Posted December 29, 2004 Share Posted December 29, 2004 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..... Link to comment Share on other sites More sharing options...
Doxie Posted December 29, 2004 Share Posted December 29, 2004 Do you wanna delete the whole content of the file, a line or just a specific word? Were ever i lay my script is my home... Link to comment Share on other sites More sharing options...
themax90 Posted December 29, 2004 Share Posted December 29, 2004 A combination of _FileCountLines and deleting the file? Or opening the file in a write(overwrite existing contents) flag? Some kinda form of it? Link to comment Share on other sites More sharing options...
DaLiMan Posted December 29, 2004 Author Share Posted December 29, 2004 @ 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 More sharing options...
SlimShady Posted December 29, 2004 Share Posted December 29, 2004 I will make an example script for you that does that. Link to comment Share on other sites More sharing options...
Insolence Posted December 29, 2004 Share Posted December 29, 2004 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 More sharing options...
Coffee Posted December 29, 2004 Share Posted December 29, 2004 (edited) FileOpen ( "filename", mode ) Parametersfilename 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 December 29, 2004 by Coffee Link to comment Share on other sites More sharing options...
Insolence Posted December 29, 2004 Share Posted December 29, 2004 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 More sharing options...
SlimShady Posted December 29, 2004 Share Posted December 29, 2004 Sorry, I've been busy. I thought I could make it in 5 minutes but something came up. Link to comment Share on other sites More sharing options...
DaLiMan Posted December 29, 2004 Author Share Posted December 29, 2004 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. Link to comment Share on other sites More sharing options...
herworth Posted December 29, 2004 Share Posted December 29, 2004 (edited) 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 December 29, 2004 by herworth [u][font="Arial"]Pete[/font][/u] Link to comment Share on other sites More sharing options...
program builder Posted March 11, 2009 Share Posted March 11, 2009 (edited) 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 todo it, so I am not lazy, but would like help figuring it out. thanks, I would appricate it. Edited March 11, 2009 by program builder Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now