Jump to content

Recommended Posts

you are finding out why.

 

Hints Appreciated :)

TD :)


A cross-platform implementation of the AutoIt language

My contributions to the AutoIt Community ##AutoIt at freenode, real-time chat

3fHNZJ.gif

Spoiler

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) intend to do that to anybody.

Share this post


Link to post
Share on other sites

Can't you add this information at the end of the file? Or in a second file with the same name but a different filetype? Or in a ADS?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2019-10-24 - Version 1.4.14.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2019-07-24 - Version 1.3.6.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (NEW 2019-11-07 - Version 1.3.0.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Can't you add this information at the end of the file?

Yes, I can, but still I would like to know if there is a way....

Or in a ADS?

Would you mind expanding "ADS"?

TD :)


A cross-platform implementation of the AutoIt language

My contributions to the AutoIt Community ##AutoIt at freenode, real-time chat

3fHNZJ.gif

Spoiler

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) intend to do that to anybody.

Share this post


Link to post
Share on other sites

Alternate Data Streams. A feature of the NTFS filesystem.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2019-10-24 - Version 1.4.14.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2019-07-24 - Version 1.3.6.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (NEW 2019-11-07 - Version 1.3.0.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Thanks water, I want my log files to survive in ext file-systems too :)


A cross-platform implementation of the AutoIt language

My contributions to the AutoIt Community ##AutoIt at freenode, real-time chat

3fHNZJ.gif

Spoiler

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) intend to do that to anybody.

Share this post


Link to post
Share on other sites

As long as it is NTFS you are fine.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2019-10-24 - Version 1.4.14.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2019-07-24 - Version 1.3.6.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (NEW 2019-11-07 - Version 1.3.0.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I do not think ADS survives transport from one disk to another does it?

If transferred internally using 2 hard-disk in the same system with NTFS file system being used in both hard-disks, It will survive....

(Or a USB formatted in NTFS would carry the file safely :))


A cross-platform implementation of the AutoIt language

My contributions to the AutoIt Community ##AutoIt at freenode, real-time chat

3fHNZJ.gif

Spoiler

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) intend to do that to anybody.

Share this post


Link to post
Share on other sites

ADS is ignored "when the file is copied or moved to another file system without ADS support, attached to an e-mail, or uploaded to a website."


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2019-10-24 - Version 1.4.14.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2019-07-24 - Version 1.3.6.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (NEW 2019-11-07 - Version 1.3.0.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Here is a VERY simple way to add something to the start of a text file.

#include <FileConstants.au3>
$sFilename = @ScriptDir & "\Test.txt"
$hFile = FileOpen($sFilename, 2) ; create new file
For $I = 1 to 10000
    FileWriteLine($hFile, "Line: " & $I) ; create 10,000 lines of text
Next
FileClose($hFile) ; close the file

; Only this part is needed to add something to the start of the file, the top part is just to create the test file.

$hFile = FileOpen($sFilename, 1) ; open file for append
FileSetPos($hFile, 0, $file_begin) ; move the file pointer to the start of the file
FileWriteLine($hFile, "I am line No. 1 now :P") ; write the line to the file
FileWriteLine($hFile, " "); write a blank line to the file
FileClose($hFile)

It never reads the file itself, so it doesn't matter how large it is.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

When file was created:

Line: 1
Line: 2
Line: 3
Line: 4
Line: 5
Line: 6
Line: 7
...

 

After the script has ended:

I am line No. 1 now :P
 
Line: 4
Line: 5
Line: 6
Line: 7

...

 

So it doesn't insert lines but simply overwrites them.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2019-10-24 - Version 1.4.14.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2019-07-24 - Version 1.3.6.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (NEW 2019-11-07 - Version 1.3.0.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Writing 5 years worth of log into a single file is extremely unwieldy. How about getting Cygwin and writing an awk or perl oneliner to divide the logfile into multiple files, say per day or per month? Or even make an autoitscript to do that? IMHO that would be a much better use of your time.

If I were you, I would go looking for a way to have the base application rotate its logfiles and/or reconfigure the logging properties. If not possible, plan B would be to write some sort of daily repeating operation (like a cronjob) to rename the logfile to another name (logfile.<date> comes to mind) as a sort of deus-ex-machina log rotation mechanism. Don't know if there's enough letters in the alphabet to assign a 5-years-old-but-still-active logfile a plan letter :)


Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites

@SadBunny You can refer to >this post

TD :)


A cross-platform implementation of the AutoIt language

My contributions to the AutoIt Community ##AutoIt at freenode, real-time chat

3fHNZJ.gif

Spoiler

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) intend to do that to anybody.

Share this post


Link to post
Share on other sites

TheDcoder, did you even bother looking at the two links I posted?

If Not FileExists(_CygwinDir()) Then ;if cygwin directory doesnt exist on system drive
    MsgBox(16, 'Error', 'Please install Cygwin [http://cygwin.com/install.html]')
    Exit
ElseIf Not FileExists(_CygwinDir() & '\bin\ed.exe') Then ;if ed.exe doesn't exist
    MsgBox(16, 'Error', 'Please ensure ed package for Cygwin is installed - it is located under Editors in the Cygwin installer [http://cygwin.com/install.html].')
    Exit
EndIf

$sFilename = _CygwinDir() & '\home\' & @UserName & '\test.txt'
$hFile = FileOpen($sFilename, 2) ; create new file
For $i = 1 to 10000
    FileWriteLine($hFile, "Line with some text: " & $i) ; create 10,000 lines of text
Next
FileClose($hFile) ; close the file

$myfile = 'test.txt'
$command = "ed -s "&$myfile&" << 'EOF'"&@CR&"0a"&@CR&"prepend these lines"&@CR&"to the beginning"&@CR&"."&@CR&"w"&@CR&"EOF"

$cygwin = ShellExecute(_CygwinDir() & '\Cygwin.bat') ;run cygwin
$hWnd = WinWaitActive('~') ;wait for console
ControlSend($hwnd, "", "", $command) ;send ed command
ControlSend($hwnd, "", "", "{ENTER}") ;execute command
Sleep(1000)
WinKill($hWnd)
MsgBox(0, 'Done', "Ta-Da!")
ShellExecute(_CygwinDir() & '\home\' & @UserName & '\') ;open the home directory

Func _CygwinDir()
    Local $CygwinDir
    Switch @OSArch
        Case "X86"
            $CygwinDir = "\cygwin"
        Case "X64"
            $CygwinDir = "\cygwin64"
    EndSwitch
    $systemdrive = EnvGet('systemdrive')
    Return $systemdrive & $CygwinDir
EndFunc

That's one way of doing it.

I'm sure its also doable without having the cygwin window visible (probably by just passing command as an argument) but it is beyond my autoit/programming skills.

Edited by mpower

Share this post


Link to post
Share on other sites

TheDcoder, did you even bother looking at the two links I posted?

Sorry mpower, When I saw the word "cygwin" my mind instantly ignored your post... Although your idea works but installing cygwin is a burden in itself. I need a more simple & universal way of doing it, hope you don't mind my ignorance or rude kind of behavior :)

Your work is greatly appreciated :)

TD :D


A cross-platform implementation of the AutoIt language

My contributions to the AutoIt Community ##AutoIt at freenode, real-time chat

3fHNZJ.gif

Spoiler

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) intend to do that to anybody.

Share this post


Link to post
Share on other sites

Sorry about the post above, lack of proper testing on my part. This script will not overwrite the text in the file, but will add the new text above it.

;~ #include <FileConstants.au3>
#include <File.au3>
$sFilename = @ScriptDir & "\Test.txt"
$hFile = FileOpen($sFilename, 2) ; create new file
For $I = 1 To 10000
    FileWriteLine($hFile, "Line: " & $I) ; create 10,000 lines of text
Next
FileClose($hFile) ; close the file

; Only this part is needed to add something to the start of the file, the top part is just to create the test file.
$hFile1 = FileOpen(@ScriptDir & "\Dummy.txt", 2) ; create dummy file, can be deleted later in the script or reused for other files
FileWriteLine($hFile1, "I am line No. 1 now :P ") ; write the line to the file
FileWriteLine($hFile1, " ")
FileClose($hFile1) ; close the file
RunWait(@ComSpec & " /c copy /b " & @ScriptDir & "\Dummy.txt + " & $sFilename & " " & @ScriptDir & "\test1.txt", "", @SW_HIDE) ; copy the dummy file to the top of the text file and create a new temp file
FileMove(@ScriptDir & "\test1.txt", $sFilename, $FC_OVERWRITE) ; overwrite the original file with the temp file, deleting the temp file

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

 

Sorry about the post above, lack of proper testing on my part. This script will not overwrite the text in the file, but will add the new text above it.

;~ #include <FileConstants.au3>
#include <File.au3>
$sFilename = @ScriptDir & "\Test.txt"
$hFile = FileOpen($sFilename, 2) ; create new file
For $I = 1 To 10000
    FileWriteLine($hFile, "Line: " & $I) ; create 10,000 lines of text
Next
FileClose($hFile) ; close the file

; Only this part is needed to add something to the start of the file, the top part is just to create the test file.
$hFile1 = FileOpen(@ScriptDir & "\Dummy.txt", 2) ; create dummy file, can be deleted later in the script or reused for other files
FileWriteLine($hFile1, "I am line No. 1 now :P ") ; write the line to the file
FileWriteLine($hFile1, " ")
FileClose($hFile1) ; close the file
RunWait(@ComSpec & " /c copy /b " & @ScriptDir & "\Dummy.txt + " & $sFilename & " " & @ScriptDir & "\test1.txt", "", @SW_HIDE) ; copy the dummy file to the top of the text file and create a new temp file
FileMove(@ScriptDir & "\test1.txt", $sFilename, $FC_OVERWRITE) ; overwrite the original file with the temp file, deleting the temp file

This takes the cake, well done! I stand corrected, cygwin is not needed after all :P 

I thought your solution might have problems with larger files but after testing on a ~140mb file with 10,000,000 lines it took only 0.2 seconds to prepend the lines. I am confident it will work with much larger files without any issues also.

Share this post


Link to post
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

  • Similar Content

    • By IAMK
      Hello,
      Can someone explain what I've done wrong?
      The code is supposed to call a function which brings up a GUI with "Pass" and "Fail" buttons. $pass is True/False, using in the following code:
      Func getStatus($pass) If($pass = "True") Then Return " passed " Else Return " failed " EndIf EndFunc I write a line to a .txt file, saying whether Step # passed or failed and how long it took. Then, if the button pressed was "Fail", an InputBox was created, which is the "Return" of SanityCheckGUI() which goes into $failLog. Refer to code below:
      Local $failLog = SanityCheckGUI($pass, $stepMessage[$step]) ;Returns a message to log if the step failed. FileWrite($filename, _Now() & ": Step " & $step & getStatus($pass) & "and took " & (TimerDiff($timer) / 1000) & " seconds." & @CRLF) If($failLog <> "") Then FileWrite($file, _Now() & ": " & $failLog & @CRLF) EndIf However... this is what I actually get when I press:
      Pass: (This is correct)
      14/11/2017 12:30:27 PM: Step 2 passed and took 1.48731919633846 seconds.
      Fail: (How does "jfuer6", the thing I put into the InputBox, come before the long line and cut it in half?)
      14/11/2017 12:29:54 PM: jfuer6
      ailed and took 4.73581847206323 seconds.
      Expected for Fail:
      14/11/2017 12:29:54 PM: Step 2 failed and took 4.73581847206323 seconds.
      14/11/2017 12:29:54 PM: jfuer6
      Thank you in advance.
    • By wimhek
      Is it possible , and how can I read and write txt files from Icloud (apple service) ?
      Let me try to explain my application.
      On my Ipad and Iphone I create txt files. On my windows computer it is possible to read and modify these files manually, by logging in on www.icloud.com.
      What I want to make is an auto-it script who reads the txt file and create an new txt file on www.icloud.com,  so I can acces these on my ipad and/or phone.
       
      Thank you.
    • By carl1905
      This code will read text data from txt file. However, if I use '$Newtext &= $convert' then $convert is saved as strings, not hex value.
      For example, if $convert = 0x300020FF and $bNewText = Test then the result is 0x333030303230464654657374. (Wrong)
      What I want is 0x300020FF54657374. How can I modify my script?
      For $i = $y-1 To Ubound($split) - 1 $convert = "0x" & $split[$i][0] $Newtext &= $convert $NewLen_hex = BinaryLen ($convert) $i=$i+1 $split[$i][1] = $split[$i][0] $split[$i][1] = StringRegExpReplace($split[$i][1], "<cf>", @CRLF) $split[$i][1] = StringRegExpReplace($split[$i][1], "<lf>", @LF) $split[$i][1] = StringRegExpReplace($split[$i][1], "<cr>", @CR) $bNewText = _WinAPI_WideCharToMultiByte($split[$i][1], $CP_SHIFT_JIS) if $i = Ubound($split) - 1 Then $bNewText &= Chr(0) EndIf $Newtext &= $bNewText $NewLen = $NewLen_hex + BinaryLen ($bNewText) Next (...) (...) $Newfile = BinaryMid($Newfile_header,1) & BinaryMid($Newtext,1) $hNewfile = FileOpen ("NEW_"&$Name, 2+16) FileWrite ($hNewfile, $Newfile) FileClose ($hNewfile) TrayTip ("Importer", "Finish!", 3) sleep (3000)  
    • By Skysnake
      Hi there
      I have searched and found many posts on READING CSV.  What I need to do is WRITE CSV.
      Typically I have a Listview, I use @guinness's excellent  _GUICtrlListView_CreateArray to read that LV to Array. Currently I use _FileWriteFromArray to write the output.  It is fast and it is easy.
      The benefits of using these Array functions are their inherit flexibility.  The code is portable.  Plug it into LV report and you can write to file instantly.  No formatting issues.
      To be sure, my problem is not with the Listview or Array.  My problem is with the file write to CSV: it should be fast, accurate and efficient.
      Part of the problem is Microsoft Excel's insistence that my CSVs are not what they appear to be...
       
      I am inspired by the simplicity of SQLITE3.EXE's dot command options:
      .headers on .mode csv .once output.csv  
      Problem is that I want to export the text packed in characters, such as ' " ' with fields delimited by another character, such as ' , '.
      Current method using _FileWriteFromArray outputs data like this
      12-04-2016| 0.00| 131.00|131|Description 12-04-2016| 0.00| 132.00|132|Description 132 rece 12-04-2016| 998.00| 0.00|998|Description Receipt 12-04-2016| 0.00| 900.00|900|Description What I want to achieve is this:
      "12-04-2016"," 0.00"," 131.00","131","Description" "12-04-2016"," 0.00"," 132.00","132","Description 132 rece" "12-04-2016"," 998.00"," 0.00","998","Description Receipt" "12-04-2016"," 0.00"," 900.00","900","Description" I have done this. The long way. I have written the output one $aResult[$i][1] item at a time, spaced with the $text & $field markers.  I have placed this in an array with additional columns just to fit in the formatting. I have also played with the idea of inserting the array into a sqlite db, then run sqlite3's dot commands on that.
      Is there a different method?  Is there an efficient method to specify FileWriteFromArraytoCSV?  Does anyone have ideas?  I am sure I will know how to code this, I just need advice on the most efficient way of going about it. If I missed any threads, please enlighten  me.
      Thanks for reading
    • By cherrylatte
      Hello,
      I would like to make a script like the below
      open the browser > copy the url in the browser's address bar > save it in a text file
      I have no clue on how to make this
      I'd appreciate for any help
×
×
  • Create New...