NSearch Posted December 2, 2005 Share Posted December 2, 2005 Can anyone think of a way to remove all single quotes, along with some other characters from a DAT file without opening up the file and stripping characters from the string. Thanks. Link to comment Share on other sites More sharing options...
Valuater Posted December 2, 2005 Share Posted December 2, 2005 FileDelete() 8) Link to comment Share on other sites More sharing options...
NSearch Posted December 2, 2005 Author Share Posted December 2, 2005 FileDelete() deletes a file. I would like to remove characters from within the file. Link to comment Share on other sites More sharing options...
MHz Posted December 2, 2005 Share Posted December 2, 2005 As a DAT file can be almost anything that holds data, then your question is very extensive to answer. Is it a binary or file or a text file format? You can also find a DAT file on a VCD that holds the mpeg information that plays the video and audio. If this file is in plain ansi text format, then you should be able to use FileOpen(), read each line with FileReadLine() and then use StringReplace() to remove the single quotes. Then write it back to a file with FileWriteLine(). Use FileClose() to finish the task. Note: This does mean opening the file and stripping from strings which is against your first post, but is rather impossible otherwise with doing it without. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted December 2, 2005 Moderators Share Posted December 2, 2005 FileDelete()8)Ha... I sense an attempt at humor in that reply Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
NSearch Posted December 2, 2005 Author Share Posted December 2, 2005 It is an EDI file with no extension. Sorry for being so vague. When I open the file in notepad, it is plain text. Link to comment Share on other sites More sharing options...
MHz Posted December 2, 2005 Share Posted December 2, 2005 The file sounds ok to edit. You could avoid opening the original file by copying it to a temp place open, read, replace single quotes, write, close, then move it over to overwrite the original. That saves opening the original but you are still stripping strings. Link to comment Share on other sites More sharing options...
NSearch Posted December 2, 2005 Author Share Posted December 2, 2005 I have been searching for some batch files. I hope that I will be able to replace the characters this way rather than writing script to perform this action. Link to comment Share on other sites More sharing options...
Valuater Posted December 2, 2005 Share Posted December 2, 2005 maybe like this #include <String.au3> $C_Text_location = @ScriptDir & '\10-20-2005.txt'; place your file location here clean_text( $C_Text_location) Func clean_text( $C_Text_location) Local $Cfile, $Cchars $Cfile = FileOpen($C_Text_location, 0) ; Check if file opened for reading OK If $Cfile = -1 Then MsgBox(0, "Error", "Unable to open C list " ) Exit EndIf ; Read in 1 line at a time until the EOF is reached While 3 $Cchars = FileReadLine($Cfile) If @error = -1 Then ExitLoop If StringInStr($Cchars,"'") then StringReplace($Cchars,"'","") If StringInStr($Cchars,"'") then StringReplace($Cchars,"'",""); place other charaters here - add more as needed FileWrite("C:\Temp\test.txt", $Cchars) Wend FileClose($Cfile) EndFunc 8) Link to comment Share on other sites More sharing options...
herewasplato Posted December 2, 2005 Share Posted December 2, 2005 (edited) Or maybe like this:$text = FileRead("c:\temp\test.txt", FileGetSize("c:\temp\test.txt")) FileOpen("c:\temp\test.txt", 2) FileWrite("c:\temp\test.txt", StringReplace($text,"'",""))...you can add the extra code for error checking and file closing if you wish.EDIT: You did say, "...remove all single quotes, along with some other characters..."$text = FileRead("c:\temp\test.txt", FileGetSize("c:\temp\test.txt")) $text = StringReplace($text,"'","") $text = StringReplace($text,"/","") $text = StringReplace($text,"\","") FileOpen("c:\temp\test.txt", 2) FileWrite("c:\temp\test.txt", $text)...or you could learn about "Regular Expressions"... I've not.@Valuater,FileDelete()Humor or just the only correct answer given this stipulation from the OP, "...without opening up the file..."?:-) Edited December 2, 2005 by herewasplato [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
Valuater Posted December 2, 2005 Share Posted December 2, 2005 >PLato FileDelete() Humor or just the only correct answer given this stipulation from the OP, "...without opening up the file..."? :-) >SmOke_N Ha... I sense an attempt at humor in that reply wink.gif yes.... both answers are correct 8) Link to comment Share on other sites More sharing options...
PartyPooper Posted December 2, 2005 Share Posted December 2, 2005 If StringInStr($Cchars,"'") then StringReplace($Cchars,"'","") If StringInStr($Cchars,"'") then StringReplace($Cchars,"'",""); place other charaters here - add more as needed 8) Sorry to hijack this thread slightly, but why is it you can use an If-Then statement here and get away without using an EndIf? Is there somewhere in the Help File I can read more on this? Cheers Link to comment Share on other sites More sharing options...
Valuater Posted December 2, 2005 Share Posted December 2, 2005 If...Then --------------------------------------------------------------------------------Conditionally run a single statement.If <expression> Then statement Parametersexpression If the expression is true, the statement is executed. RemarksThis version of the If statement is used to execute a single statement without the overhead of an EndIf.The expression can contain the boolean operators of AND, OR, and NOT as well as the logical operators <, <=, >, >=, =, ==, and <> grouped with parentheses as needed. RelatedIf...Else...EndIf, Select...Case...EndSelect Example;Terminates script if no command-line argumentsIf $CmdLine[0] = 0 Then Exit;Alternative:If $CmdLine[0] = 0 Then ExitEndIf8) Link to comment Share on other sites More sharing options...
FuryCell Posted December 2, 2005 Share Posted December 2, 2005 (edited) Sorry to hijack this thread slightly, but why is it you can use an If-Then statement here and get away without using an EndIf? Is there somewhere in the Help File I can read more on this?CheersYou only need "EndIfs" for multiline "If" statements.If it is a single line "If" (like the one you are asking about) then no "EndIf" is needed. Edited December 2, 2005 by SolidSnake HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code. Link to comment Share on other sites More sharing options...
PartyPooper Posted December 2, 2005 Share Posted December 2, 2005 Thanks Guys. 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