Funtime60 Posted September 21, 2022 Posted September 21, 2022 I'm pretty sure this isn't the first time I've ran into this issue with _FileWriteToLine. I was trying to edit a large file in place without creating a temporary file. I tried to use _FileWriteToLine as I needed to replace a specific lines with a line of equal length. The issue I ran into is that _FileWriteToLine both reopens the file, then reads it entirely into an array, thus defeating the purpose I was using it for. (Which IIRC isn't mentioned in the help file). In fact I can think of few cases where it isn't just better to do what _FileWriteToLine is doing manually. TL:DR if you want to REPLACE characters in a file without loading the entire file into memory, you'll need to use FileSetPos and FileWriteLine. In case it wasn't clear, I'm writing this so that others and future me don't make the same mistake.
Moderators Melba23 Posted September 21, 2022 Moderators Posted September 21, 2022 Funtime60, Quote _FileWriteToLine both reopens the file, <...>. (Which IIRC isn't mentioned in the help file) The Help file does mention that "A file may fail to open due to access rights or attributes"- which to me implies quite clearly that the function does open files when used. And just how do you intend to modify a file without reading it into memory? Rewrite the values stored on the disk directly? Sounds like a quick route to disaster to me! M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
HurleyShanabarger Posted September 21, 2022 Posted September 21, 2022 3 hours ago, Funtime60 said: TL:DR if you want to REPLACE characters in a file without loading the entire file into memory, you'll need to use FileSetPos and FileWriteLine. Thank you for the tip, but I think overwriting would be the better term. Also you need to know the position for FileSetPos beforehand, as FileSetPos is reffering to the actual position in a file and not a line.
Zedna Posted September 22, 2022 Posted September 22, 2022 To get posion of desired line in file you can read content of file by chunks in While loop and count number/position of each @CRLF in chunks. After this While loop use FileOpen() + FileSetPos() + FileRead() + FileWrite() + FileClose() to overwrite only desired line in file. Resources UDF ResourcesEx UDF AutoIt Forum Search
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