Modify

Opened 18 years ago

Closed 17 years ago

Last modified 16 years ago

#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 by TicketCleanup, 18 years ago

Version: 3.2.10.0

Automatic ticket cleanup.

comment:2 by Valik, 18 years ago

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 by flyingboz, 18 years ago

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 by TicketCleanup, 18 years ago

Milestone: Future Release

Automatic ticket cleanup.

comment:5 by Valik, 18 years ago

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 by flyingboz <flyingboz@…>, 18 years ago

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 by Valik, 18 years ago

If insertion were to be provided, I would prefer to see it done in a separate function.

comment:8 by flyingboz , 18 years ago

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 by Valik, 18 years ago

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 by Valik, 17 years ago

Milestone: 3.3.1.0
Owner: set to Valik
Resolution: Completed
Status: newclosed

Added in version: 3.3.1.0

comment:11 by Zedna, 17 years ago

Just note:

Already implemented as UDF --> _WinAPI_SetFilePointer()

comment:12 by Valik, 17 years ago

Severity: None

The function you mention does not work with built-in file functions.

comment:13 by Zedna, 17 years ago

Aah. Of course you are right Valik.
Sorry then.

Modify Ticket

Action
as closed The owner will remain Valik.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.