Jump to content

Automatically append to beginning of file


Recommended Posts

FileFindFirstFile

For ...

FileFindNextFile

FileRead

... append the 3 lines to the content

... create backup of original file

... empty original file content (FileOpen flag 2)

FileWrite (new content)

FileClose

Next

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

This should work

$filefind = FileFindFirstFile(@ScriptDir & "\*.php")

While 1
    $file = FileFindNextFile($filefind)
    If @error = 1 Then ExitLoop
    $previoustext = FileRead(@ScriptDir & "\" & $file)
    $fileopen = FileOpen(@ScriptDir & "\" & $file, 2)
    FileWrite($fileopen, "your 1st line" & @CRLF & "your 2nd line" & @CRLF & "your 3rd line" & @CRLF & $previoustext)
    FileClose($fileopen)
WEnd

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Link to comment
Share on other sites

there are also _FileReadToArray & _FileWriteFromArray functions. they are pretty useful, but if you have tons of files & looking for a little bigger speed go with the sample above. Cuz arrays are wery slow.

It takes times to write the whole file tho. So if you have 1 million files it will still be slow. In this case, there are other ways to do it, like hex edit the file. im not sure how much speed you will gain tho.

My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]
Link to comment
Share on other sites

For future reference, the operation is "prepend" or "prefix", not "append".

I'm not trying to be the grammar-Nazi, it's just that some languages have append() and prepend() operations or operator symbols, and it would be good to call for the right one.

:(

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...