Sign in to follow this  
Followers 0
trynhyty

FileWrite and delete char

4 posts in this topic

Hi everybody, new here.

I'm messing around with AutoIT since a few days. 

I'm actually doing some experiment on my computer, and want to do a simple textbox on my desk, and when I type some things like "chrome" then click OK or input Enter, it launch chrome.exe

Anyway, I'm storing a historic of my inputs in a txt file. And if I push my BackSpace button, I'd like to make my code delete the last character of the txt file instead of FileWrite ($historic, 'BACKSPACE') .. 


 Is there a special character that can delete my last char in the txt file ? I remember doing domething like that in C but it was years ago and I was beginning... 

Thanks for your help ! :)

Share this post


Link to post
Share on other sites



This should help you get started: StringTrimRight


Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

This should help you get started: StringTrimRight

Thanks MikahS, 

So, if I understand, I have to read the whole .txt file as a string, remove 1 char from this string, and write the result in the .txt file ? 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

There are many ways you can go about doing this. I like using the _FileReadToArray, depending on if you have a way to split the lines (otherwise just do FileOpen w/ overwrite, FileRead, StringTrimRight, FileWrite, FileClose), use the count, which would be under index 0, and trim the string as you see fit, then write the array back using _FileWriteFromArray with FileOpen in overwrite mode. 

Let me know if you have any questions, as there is multiple ways of going about achieving what you would like.

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

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
Sign in to follow this  
Followers 0

  • Similar Content

    • wimhek
      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.
    • visler
      By visler
      Hi all

      I been using autoit some years ago and needed a tool for changing various in outlook so i found autoit again and i allready succeed in some of this, but i cant find and delete an appointment.
      I have found this example and the creation is ok (after i changed $oOL/$oOutlook typo)
      Https://www.autoitscript.com/wiki/OutlookEX_UDF_-_Meeting_Item
      But i cant get the delete part to work and i keep on getting "not found" and an empty array (screen shoot of _ArrayDisplay attached)
      Please can someone tell me what i am missing, i have been searching and trying various but stil i have no luck in finding any items.

      I am using outloook 2013 and office365. I have been able to send mails and create appointment, so i guess my problem is not due to the use off office365.

       

    • Vivaed
      By Vivaed
      I am trying to read all the files in a folder, then whatever file is newest, keep only that one and delete the rest.
      Example files:  (these all have version numbers embedded in them, I dont want to rely on the file name)
      Faint.exe
      Faint-v2.0.exe
      Faint-v3.0.exe
      Faint-v4.0.exe
       
      What I have so far:
      #include <File.au3> RemoveOldFiles() ConsoleWrite(FileGetVersion("C:\WB Resources\FAINT_DONT_LINK_THESE\Faint-v4.0.0.exe") &@CRLF) Func RemoveOldFiles() Local $aFileList = _FileListToArray("C:\WB Resources\FAINT_DONT_LINK_THESE\", "*.exe",$FLTA_FILES) For $i = 0 To UBound($aFileList) - 1 $aFileVersion = FileGetVersion($aFileList[$i]) ConsoleWrite($aFileList[$i] & @CRLF) ConsoleWrite($aFileVersion & @CRLF) Next EndFunc OUTPUT: >Running:(3.3.14.2):C:\Program Files (x86)\AutoIt3\autoit3_x64.exe "C:\Users\bot\ownCloud\WellBeats\Delete Old Files\delete-test.au3" --> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop 3 0.0.0.0 a.exe 0.0.0.0 b.exe 0.0.0.0 Faint-v4.0.0.exe 0.0.0.0 4.0.0.18 <-- This is the correct file version.... +>07:34:26 AutoIt3.exe ended.rc:0 +>07:34:26 AutoIt3Wrapper Finished. >Exit code: 0 Time: 0.6647 Not sure what I am missing here?
      Thanks!
    • carl1905
      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)  
    • Skysnake
      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