Search the Community
Showing results for tags 'fileread'.
-
I've noticed that for the task of "reading a file row by row into an array" FileReadToArray is consistently slower than a FileRead + StringSplit. The following script: Results in the following output for me: And the output with switched call sequence: This surprises me, since I first assume that the native function offers more optimization possibilities than having to create an array in AutoIt via an intermediate string. So I thought that maybe FileReadToArray is more economical with memory. But again FileReadToArray seems to consume more memory than the StringSplit variant. For this I got the PeakWorkingSetSize after the call of the respective function. After FileReadToArray the Size is always higher than with StringSplit. Since this is not the case if one changes the order of the two functions (see above), one can assume that FileReadToArray actually has this difference. The difference is mostly the double file size. Which would make sense if the file is completely saved internally as a UTF-16 string. Can anyone explain to me why FileReadToArray performs so unexpectedly poor - or am I missing something?
- 14 replies
-
- filereadtoarry
- stringsplit()
-
(and 1 more)
Tagged with:
-
Hello all A programme I wrote for the organisation for which I work has been in use for a number of years with no issue. One of the things that it does is allow for attachments to be selected (Word docs, Excel sheets, etc) which it then writes away as a BLOB in MySQL. This was all working fine until recently, when suddenly, on the odd occasion, Word would advise that the file was corrupt on retrieval of the BLOB from MySQL. Upon further examination it appears that the issue is not with the retrieval of the data from MySQL, but reading in the data from the disk by AutoIT. It seems that on occasions that AutoIT will only read half the file. I have no idea why this is, as the whole function is very simple. I have included a sanitised vesion of it below in the hope that someone can tell me where to look next, as this one has me beat (again). 😋 I have put some comments in to show what I have done to try and solve the problem, but am getting no closer to the truth. @error is the strangest one - it should return -1 when it reaches end of file but is returning zero. Func _AttachAttachment() local $file,$chars,$fsize If $RFC_Retrieved = False Then msgbox(0,"Error","Must have a RFC active first") Else $file=FileOpenDialog("Attach to RFC",".","All (*.*)",1) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf ; FileClose($file) These two lines are my attempt to open the file in binary mode. Made no difference ; FileOpen($file,16) ; Read in the File $fsize = FileGetSize($file) ConsoleWrite("File size is " & $fsize & @CRLF) ; the size comes back as what it say in Windows properties ; $chars = FileRead($file,$fsize) ; I was using this, then tried the line following this. It didn't help $chars = FileRead($file) ; This is showing a figure $chars/2 - 1 I don't understand this ConsoleWrite("Number of chars read is " & @extended & " error code is " & @error & @crlf) ; @error is coming back with 0. I don't understand this as I thought it would be -1 FileClose($file) EndIf EndIf EndFunc Thanks in advance for looking at this Clark
-
I've made a program that relies on IniReadSectionNames. It reads (~3K) Autorun.inf files in the working folder and creates a GUI based on their contents. I made sure to revert to a default GUI upon @error. But someone (with Windows XP SP3 32-bit) reported to me he always gets the default menu. I sent him a FileRead command instead and it works! So seemingly there's no access problem to AutoRun.inf. In the following demo code, I always hit success, but he always ends up with semi-success: Local $hIniLocation = "Autorun.inf" Local $aSections = IniReadSectionNames($hIniLocation) If @error Then $aSections = FileRead($hIniLocation) if @error then msgbox(48, "Double error", "Alternative access failed too due to:" & @crlf & @error & @crlf & @extended) else msgbox(0, "Semi-success", "IniReadSectionNames failed, but alternativaly this file contains:" & @crlf & @crlf & $aSections) endif else msgbox(0, "Success", "IniReadSectionNames worked!") endif Why is that? Is there something further to check with him? Autorun.inf
-
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.
-
Hi to all, I am writing a feature to an existing internal AutoIt program, based on a client's request. The requested feature would be to grab the file via a button, which reads the file's path. Below the file browsing button would be a button to upload the file into a MySQL server. Initially, my method would be to read the contents of the file provided in the filepath, then convert the contents of the file into binary data, and then store it into a column of a table as a BLOB. I am not sure whether if this is the best approach to storing text/Word/PDF files into the MySQL Server in this way, if the program used is an AutoIt program. So far, I am only able to generate Excel files, but only because there was already an existing BLOB column in an existing table. Sample code: $sTemplateName = "SearchTemplate" $sFilePath = @ScriptDir & "\temp\" & $sTemplateName & ".xls" $iFileExists = FileExists($sFilePath) ; If template file not found, create it. If (Not $iFileExists) Then generateExcelFile($sTemplateName, $sFilePath) EndIf $iFileExists = FileExists($sFilePath) If $iFileExists = 1 Then $oExcel = _ExcelBookOpen($sFilePath, 0) _ExcelWriteCell($oExcel, "Search conducted on " & _NowCalc() & " by " & $username & "", 2, 1) $counter = 0 While Not $recordSet.EOF _ExcelWriteCell($oExcel, 1 + $counter, 6 + $counter, 1) _ExcelWriteCell($oExcel, getName("User", $recordSet.Fields("UserID").value), 6 + $counter, 2) _ExcelWriteCell($oExcel, $recordSet.Fields("InternalName").value, 6 + $counter, 3) _ExcelWriteCell($oExcel, getName("Product", $recordSet.Fields("ProductID").value), 6 + $counter, 4) _ExcelWriteCell($oExcel, $recordSet.Fields("Serial").value, 6 + $counter, 5) _ExcelWriteCell($oExcel, getName("Location", $recordSet.Fields("LocationID").value), 6 + $counter, 6) _ExcelWriteCell($oExcel, $recordSet.Fields("Remarks").value, 6 + $counter, 7) _ExcelWriteCell($oExcel, getFriendlyDate($recordSet.Fields("LastModified").value, 1), 6 + $counter, 8) _ExcelWriteCell($oExcel, getFriendlyDate($recordSet.Fields("CreationDate").value, 1), 6 + $counter, 9) $recordSet.MoveNext $counter = $counter + 1 WEnd _ExcelBookSaveAs($oExcel, $exportDir & "\" & $username & "_Search_Results_" & @YEAR & @MON & @MDAY & "_" & @HOUR & @MIN & @SEC, "xls") _ExcelBookClose($oExcel, 1, 0) EndIf
- 2 replies
-
- binarydata
- blob
-
(and 5 more)
Tagged with:
-
Hi, I ran a remote program on 180 computers and logged the output to a log file with paexec. I'm trying to parse through the log file to see which computers launched the program successfully and record the computer name but I'm not sure how to go about it. I can successfully open the log file, read it but not sure how to start separating the data. I've attached the log file, basically every computer entry in the log file for a new computer starts with "Connecting to <computername>..." I was thinking about using that as the start and stop point for retrieving the end results. Anything with a "returned 0" is a success, everything is a fail. Any help is much appreciated. testlogfile.txt
-
Howdy Everyone! I've been scouring the forum for something that works... and no dice yet... hoping to stop the frustration - hope someone in the forum knows what to do. Basically, I've saved .msg files out of MS Outlook and want to scan each on for email addresses but all I get with fileopen and fileread are symbols... ran through every iteration. I've seen people do some soft of binary extract and binarytostring but I haven't gotten that to work either... not sure what's going on. Neither of these have worked for me... yes I know they are old and FileOpen has changed... but like I said I tried everything that I know of. Please help $sFile = "C:\temp\messages\Test.msg" $hFile = FileOpen($sFile, 16) ; 16 = binary $binData = FileRead($hFile, 1024) ; read first 1KB FileClose($hFile) ConsoleWrite("Debug: First 1KB = " & $binData & @LF)or... $sFile = "C:\temp\messages\Test.msg" $hFile = FileOpen($sFile, 16) $binData = FileRead($hFile, 20480) FileClose($hFile) $startdef=StringTrimLeft(Binary('thetextIamlookingfor'), 20) $enddef=StringTrimLeft(Binary('moretextIamlookingfor'), 20) $binData=StringTrimLeft($binData, StringInStr($binData, $startdef)+StringLen($startdef)-1) $binData=StringLeft($binData, StringInStr($binData, $enddef)-1) ConsoleWrite(BinaryToString('0x'&$binData) & @LF) Thanks!
-
Hi guys I hope you can help me out I have a script that checks for the current user's loginname in different txt files. If the current user's loginname is found in one of the txt files, the script reacts based on that. The text files look something like this: dle oej zaq oei (different usernames) This is an example of the script: $username = @UserName ;pulls username that is logged in $Dir = "C:\Test\" Global $Custom[] = ["text01", "text02", "text03", "text04"] ;CHECK LISTS For $i = 0 To UBound($Custom) - 1 $CustomFile = FileOpen($Dir & $Custom[$i] & ".txt", 0) $Readtxt = FileRead($CustomFile) FileClose($CustomFile) If StringRegExp($Readtxt, $username) Then do this and that... EndIf NextIt works perfectly if the user logs in as xxxx or XXXX (Both lower and upper case characters) So the FileRead function doesn't seem to be case sensitive. But if the user logs in as xxXx (mix of lower and upper case characters), then the username is not recognized in the txt file. Does anyone have a suggestion on how I can fix this? Thanks in advance! - David
-
Good Morning All, I'm hoping someone here can work their AutoIT magic I'm doing a pretty "simple" string search in a HUGE variable. But I'm doing the basics almost straight out of the Help File... ( sorry, I'm leaving out my main code for privacy reasons ) Local $hFileOpen = FileOpen($sFilePath, $FO_READ) Local $sFileRead = FileRead($hFileOpen) Local $sEmailPosition01 = StringInStr ($sFileRead, $sEmailAddress )Everything looks good with my troubleshooting I ran IsString against $sFileRead and $sEmailAddress and was okay: "The variable is a string" So then I ran StringLen($sFileRead) and got string length 68352786 Yeah, I know... That's HUGE - But it worked with the older version of AutoIT (upgraded yesterday) v3.3.14.2 Is there an "Excessive" variable I should set?!? lol. Should I search the string a different way maybe? I know the string is in there... but I'm getting a StringInStr @error : 0 @extended: 0 Please help! Thank you all
- 11 replies
-
I'm attempting to decrypt a file previously encrypted with the encrypt file function; then read that file into an array and display it. When I read the file into an array it still shows me garbled text if any at all. What am I doing wrong here? $serial = "stepping through array var" $FileHandle = "C:\XXX\Serial.txt" If FileExists($FileHandle) Then $Password = "password" _Crypt_DecryptFile($FileHandle, $FileHandle, $Password, $CALG_RC4) $FileArray = 0 ;initilze computer list array _FileReadToArray($FileHandle, $FileArray) _ArrayDisplay($FileArray) ;why is this showing encrpyted data?!?! FileOpen($FileHandle) FileWriteLine($FileHandle, $serial) FileClose($FileHandle) Else FileOpen($FileHandle) FileWriteLine($FileHandle, $serial) FileClose($FileHandle) EndIf $Password = "password" _Crypt_EncryptFile( $FileHandle, $FileHandle, $Password, $CALG_RC4) Next Any help is greatly appreciated!
- 4 replies
-
- encryption
- decryption
-
(and 2 more)
Tagged with:
-
Hi everyone.. not quite sure how to get a list box to save its strings into a single .log or .txt file (either would work for me), and then later call each individual string.. the list box has up to 30 items in it, the user will be able to deselect certain items, or select items... i just need a way to save each string into an external file so i can later call them back as variables and display them into a disabled list box.. if anyone could help that would be extremely appreciated. reply if my objective is confusing. THANKS!
- 1 reply
-
- filewrite
- filewritetoline
-
(and 2 more)
Tagged with:
-
Hello I have some problems I can't get the logic on how to work on this filereadline. Here's my probs.. file1.txt 1<tab>1111<tab>NAME_TAG<tab>2222 file2.txt 1<tab>NAME_TAG<tab>The Name of Tag output.txt "1111","NAME_TAG","The Name of Tag",2222 I appreciate any help to this topic. Im not good in this kind of logic.
-
[HELP] File read all lines except last 1
Command3r posted a topic in AutoIt General Help and Support
Hello scripters i got another problem reading all lines in txt file except the last one. I dont want to write how many lines to read just reading all except the last whatever how many it is. My efforts: #include <file.au3> $file = @ScriptDir & "\x.txt" $ReadLines = FileReadLine($file) Local $Read _FileReadToArray($file, $Read) For $i = 1 To $Read - 1 ; with-1 or without-1 the result is the same MsgBox(0, $i, $Read - 1) Next Question here: "Why first msgbox title is "1" ? and how can i avoid that?" #include <file.au3> $file = @ScriptDir & "\x.txt" $ReadLines = FileReadLine($file) Local $Read _FileReadToArray($file, $Read) For $i = 1 To $Read MsgBox(0, $i, $Read[0] -1) ; here in msg's text resolved but in title not :D i think the problem from $i ?? Next- 5 replies
-
- FileRead
- FileReadLine
-
(and 1 more)
Tagged with:
-
Hello, i have 2 questions: First: Read an text file and numbering every line. Second: Write ">>>" or any text i want every first line. Ex.1 blablablablababla blablablablabala blablablablababl blablablablababb l want make texts above like that: 1- blablablablababla 2- blablablablabala 3- blablablablababl 4- blablablablababb Ex.2 blablablablababla blablablablabala blablablablababl blablablablababb Put an text at every line at first. >>> blablablablababla >>> blablablablabala >>> blablablablababl >>> blablablablababb Although i searched, i don't tried because i don't know from where should i start or try. Please post first solution in single script and second solution in single script too. Thanks.