jdicerch Posted August 1, 2013 Share Posted August 1, 2013 Thank you guys in advanced. I am trying to edit the first line of a text file, delete the first line of that file, then readd the edited line back in. For some reason, I can't even write to a specific line in a file. Let me know what I am doing wrong! This is just trying to add "000000" to the first line of that text file. #include <File.au3> $sFile = FileOpen("C:\Users\z19jmd\Desktop\test.txt", 1) _FileWriteToLine($sFile,1,"000000000",1) FileClose($sFile) Link to comment Share on other sites More sharing options...
guinness Posted August 1, 2013 Share Posted August 1, 2013 Look at _FileReadToArray and _FileReadFromArray. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Solution jdicerch Posted August 1, 2013 Author Solution Share Posted August 1, 2013 FileReadToArray wasn't what I was looking for, but thanks for the suggestion. Apparently FileWriteToLine already opens the file, so as soon as I took that out it seemed to fix it. Link to comment Share on other sites More sharing options...
Belini Posted August 1, 2013 Share Posted August 1, 2013 Example: #include <File.au3> FileWrite("test.txt", "Text of the first line" & @CRLF & _ "Text of the second line" & @CRLF & "Text of the third line") $file = FileOpen("test.txt", 0) $read = FileReadLine($file) MsgBox(4096, "Before", "First line = " & $read) _FileWriteToLine("test.txt", 1, "", 1) $file = FileOpen("test.txt", 0) $read = FileReadLine($file) MsgBox(4096, "After ", "First line = " & $read) My Codes: Virtual Key Code UDF: http://www.autoitscript.com/forum/topic/138246-virtual-key-code-udf/ GuiSplashTextOn.au3: http://www.autoitscript.com/forum/topic/143542-guisplashtexton-udf/ Menu versions of Autoit: http://www.autoitscript.com/forum/topic/137435-menu-versions-of-autoit/#entry962011 Selects first folder of letters: ]http://www.autoitscript.com/forum/topic/144780-select-folders-by-letter/#entry1021708/spoiler] List files and folders with long addresses.: http://www.autoitscript.com/forum/topic/144910-list-files-and-folders-with-long-addresses/#entry102 2926 Program JUKEBOX made in Autoit:some functions:http://www.youtube.com/watch?v=WJ2tC2fD5Qs Navigation to search:http://www.youtube.com/watch?v=lblwOFIbgtQ Link to comment Share on other sites More sharing options...
DW1 Posted August 1, 2013 Share Posted August 1, 2013 Thank you guys in advanced. I am trying to edit the first line of a text file, delete the first line of that file, then readd the edited line back in. For some reason, I can't even write to a specific line in a file. Let me know what I am doing wrong! This is just trying to add "000000" to the first line of that text file. #include <File.au3> $sFile = FileOpen("C:\Users\z19jmd\Desktop\test.txt", 1) _FileWriteToLine($sFile,1,"000000000",1) FileClose($sFile) Just so you understand why it was failing and how to find out for yourself next time, add error checking after the line that isn't working. In this case, you were returning @error = 2 (File does not exist). This is because you are passing a file handle to a function that is only looking for a file name. AutoIt3 Online Help Link to comment Share on other sites More sharing options...
jdicerch Posted August 1, 2013 Author Share Posted August 1, 2013 This is because you are passing a file handle to a function that is only looking for a file name. Thanks for answering, I always like to know where I went wrong, but what did you mean by passing a file handle? It didn't want the entire path? Link to comment Share on other sites More sharing options...
DW1 Posted August 1, 2013 Share Posted August 1, 2013 Thanks for answering, I always like to know where I went wrong, but what did you mean by passing a file handle? It didn't want the entire path? When you called fileopen, the return was a file handle, not a filename. A file handle is a reference to a file that was in this case, opened for writing (append). So actually, yes it did want the entire path, but you passed it a file handle instead. when you wrote $sFile = FileOpen... it really should have been $hFile = FileOpen... since it returns a handle not a string containing the path. AutoIt3 Online Help 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