#135 closed Feature Request (Completed)
FileWrite, FileWriteLine extended to set write mode and pointer position
Reported by: | flyingboz@… | Owned by: | Valik |
---|---|---|---|
Milestone: | 3.3.1.0 | Component: | AutoIt |
Version: | Severity: | None | |
Keywords: | FileWrite FileWriteLine Insert Overwrite Prepend "File Pointer" Position | Cc: |
Description
Suggested Syntax:
FileWrite($filehandle,$line,[$pointer_position],{$insert_or_overwrite])
Suggested Behavior
case $pointer_position >=0 AND < FileSize
insert or overwrite file contents with $line beginning at $pointer_position
case $pointer_position > filesize
move pointer to EOF
(alternatively, we could pad filesize with NUL or space), then begin writing, like the unix 'touch' function.
case $pointer_position omitted or <0
current behavior, move pointer to EOF, append $line
Benefits
Standardized methodology of inserting data into existing files at an arbitrary location.
Performance and reliability improvements dealing with large files, or files that are used by more than one process.
Provides functionality not directly present in windows api, not doable with a one line UDF / DllCall.
New parameters optional, doesn't break existing scripts.
Attachments (0)
Change History (13)
comment:1 Changed 17 years ago by TicketCleanup
- Version 3.2.10.0 deleted
comment:2 Changed 17 years ago by Valik
Where does the write pointer go after an *insertion*? Is it left at the end of the inserted text, or is it at EOF?
comment:3 Changed 17 years ago by flyingboz
If the pointer state is "lost" after each write operation, then repeated *inserts* would require additional effort to locate where the pointer should be. However, it is easily calculated as you necessarily know where you started and know or can find it how much you've written. In prepend operations, the pointer will be placed at SOF for each write operation. Other scenarios essentially involve StringInStr() / RegEx operations to determine where you want to set the position. I don't have a use case that would require preservation of the pointer position and where it would be difficult to calculate what the pointer position should be.
In summary, if the file pointer location is preserved, in the vast majority of cases it will simply be moved again to the next desired location. It would probably be safer and easier to debug if the default on completion of the write operation was to move the pointer back to EOF.
comment:4 Changed 17 years ago by TicketCleanup
- Milestone Future Release deleted
Automatic ticket cleanup.
comment:5 Changed 17 years ago by Valik
I think we should just add a function for changing the file pointer, FileSetPointer() or something. Then you can implement the logic you want in your own functions. The behavior you want is a bit more than I think a single (built-in) function should do. And I do agree that we need a way to move the file pointer around.
comment:6 Changed 17 years ago by flyingboz <flyingboz@…>
I have no objection to a FileSetPointer() function. And it is true that writing the logic to do the insert/overwrite, while straightforward, is not trivial. However, I see a tremendous upside for being able to set the insertion mode directly in a builtin function. I'd much rather the c++ do the 'heavy lifting' of reading /writing file contents on insertion operations.
I base that preference on the belief that the preservation of any file contents after the pointer position on an insert operation would be more quickly handled if the $autoit variables that otherwise would be required were kept internally and did not have to be {exposed to / populated / utilized by } the (autoit) programmer. In large files, these operations can take significant amount of time and consume large amounts of memory.
Can you comment on the relative performance merits of moving the onus of file preservation back to the scripter?
comment:7 Changed 17 years ago by Valik
If insertion were to be provided, I would prefer to see it done in a separate function.
comment:8 Changed 17 years ago by flyingboz
So you would be more open to adding one or two builtin functions, such as:
FileInsert($filehandle or "filename","text to insert",$file_pointer_position)
FileInsertLine($filehandle or "filename","text to insert",$file_pointer_position)
That with the FileSetPointer($filehandle) for being able to overwrite arbitrary file data would cover all desired functionality.
Not that my happiness is paramount here, but I could be happy with that.
The user functionality would be present, the file output features would be fully robust, and performance of insert / overwrite operations would be improved.
comment:9 Changed 17 years ago by Valik
FileInsertLine() is superfluous. I think FileWriteLine() is stupid enough. But otherwise, yes, I'd prefer to see two new functions for moving the file pointer and inserting.
comment:10 Changed 16 years ago by Valik
- Milestone set to 3.3.1.0
- Owner set to Valik
- Resolution set to Completed
- Status changed from new to closed
Added in version: 3.3.1.0
comment:11 Changed 16 years ago by Zedna
Just note:
Already implemented as UDF --> _WinAPI_SetFilePointer()
comment:12 Changed 16 years ago by Valik
- Severity set to None
The function you mention does not work with built-in file functions.
comment:13 Changed 16 years ago by Zedna
Aah. Of course you are right Valik.
Sorry then.
Guidelines for posting comments:
- You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
- In-depth discussions should take place on the forum.
For more information see the full version of the ticket guidelines here.
Automatic ticket cleanup.