Jump to content

Search the Community

Showing results for tags 'FileOpen'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • Forum FAQ
  • AutoIt

Calendars

  • Community Calendar

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Member Title


Location


WWW


Interests

Found 16 results

  1. Junior Programmer here... Not much experience with opening, changing and closing files. I am trying to replace strings in a Text file except StringReplace does not actually replace the text. Here is a sample of my code... #include <File.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> Local $iStrReturn = 0 Local $hFile Local $sText Local $sNewText ; Location of File to be read $sFileName = "C:\Temp\MyPlayer.exe.config" ; The default is FALSE. We want to change this to TRUE $bLoopChecked = True CheckBox() Func Checkbox() $hFile = FileOpen($sFileName,$FO_READ) ; Open file in read mode to get text If $hFile = -1 Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred when Opening the file.") Exit EndIf FileSetPos($hFile, 0, 0) ; No idea if I need to do this, grasping at straws $sText = FileRead($hFile) ; Read the file into $sText If $sText = 1 Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred when reading/writing the file.") Exit Else FileClose($hFile) ; Finished reading the file into $sText, so close the file. FileFlush($hFile) ; Manual says to use FileFlush between File Close and Open so here it is EndIf MsgBox(0,"Before Replacement",$sText) ; Displays the text read from the file to make sure something is there. ; Loop Check If $bLoopChecked = True Then ; Find the string return > 0 for success $iStrReturn = StringInStr('"<add key="LoopCheckbox" value=""False" />"', "False") ;MsgBox(0,"", "LoopCheckBox is " & $iStrReturn) If $iStrReturn > 0 Then ; If StringInStr returned > 0 the it found the string! ; The Meat of the code. This is where we have to replace "False" with "True" $sNewText = StringReplace($sText, '"<add key="LoopCheckbox" value="False" />"', '"<add key="LoopCheckbox" value="True" />"') MsgBox(0,"After Replacement",$sNewText) ; Display the text to see if it worked. $hFile = FileOpen($sFileName,$FO_OVERWRITE) ; Reopen the file to write to it, overwriting everything. FileWrite($hFile,$sNewText) ; Write the text to the file FileClose($hFile) ; Close the file EndIf EndIf EndFunc This is the file I am reading... <?xml version="1.0" encoding="utf-8"?> <configuration> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/> </startup> <appSettings> <add key="LoopCheckbox" value="false"/> </appSettings> </configuration> I tried opening the file with $FO_UTF8 and $FO_UTF8_NOBOM but got errors opening the file. The MsgBox "After Replacement" shows the value is still false.
  2. Hello, I need to pull data from company intranet website. I created a script that I can give a list of project numbers and it will open up the the related webpage for each project, save the html comments for that project, then move on to the next. However my problem comes in that each time I open up a project it locks it for other users, and if you just exit the page it keeps it locked, you have to actually press the "close" button on the page. So I'm not sure how to deal with this as I end up just locking every project in my name when I run my program as I don't understand the nature of how the website is built. I don't understand how to close with just using my automation code without manually having to press the stupid button. My Function: Func Getscript($ProjectAddress) ;getting the page source code and storing it into text file for easy reading it $file = FileOpen(@ScriptDir & "\source.txt", 10) $IE = _IECreate($ProjectAddress & ".html", 0, 0) $source = _IEDocReadHTML($IE) FileWrite($file, $source) $target_source = _StringBetween($source, "<BODY>", "</BODY>") ; only take content between the specified tags _IEQuit($IE) FileClose($file) return $target_source[0] EndFunc ;==>Getscript Source Code I got from website that I think is relevant: function closeForm(){ if(topButtonEnabled("closeButton")){ parent.mainFrame.closeForm(); } } <button id="closeButton" class="saveCloseButton" style="LEFT: 77px;" onclick=closeForm()>&nbsp;Close&nbsp;</button> Any Ideas of how to tell website to either activate the closeform function or just give it the command to close? Thanks
  3. Hi All, I have a script whose sole purpose is to walk through about 15,000 - 20,000 files in a single directory structure, making modifications to 5 or 6 lines within each file. Simple. I have a small splash screen that is simply counting how many files have been completed out of the overall total. The script is functioning fine and the splash screams through the initial files, but through time begins to slow to a crawl (It becomes noticeable after about 1,000 to 1,500 files). I have used a combination of methods to write to the file, but none of which appear to make much of any difference: Local $FileOpen = FileOpen($FileInList,1) FileWriteLine($FileOpen,@CRLF) FileClose($FileOpen) OR FileWriteLine($FileHandle, $NewLineString & @CRLF) OR Local $FileHandle = FileOpen($FileInList,2) _FileWriteFromArray($FileHandle,$FileContentArray,1) FileClose($FileHandle) I have checked and the CPU and memory are fine. My current work-around is to create 5-10 separate directory structures from the original one that contains 20,000 files, run the script and then combine them again in the end. It works, but isn't very portable. Any ideas? Cleanup_AutoITPost.au3
  4. 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
  5. I have a good handle on how to read a file line by line, and search for a given string. Basically using, FileOpen, FileReadLine, and StringInStr. I have been trying to figure out why my search keeps coming back with no match. For example, if my string line was "Where is Waldy", and I was searching for Waldy that comes back fine. But in my file, Let's say it is Where is "Waldy" So i read that line in and do a search for Waldy, but i comes back with no match since there is quotes around it. Is there a way to resolve this? Here is my actual example The line comes back like this <JposEntry logicalName="LineDisp_iSC480"> I'm searching for LineDisp_iSC480, but its coming back with no match due to the quotes. Thanks in advance, James
  6. Hello, In a main script I have added logging and that is working. Now I created another small script where I need also logging. So I used the same code: What is wrong? Why is the logfile not created? $default_delay = 2000 $logFilePath = ("C:\AutoIT_TestLogs") DirCreate($logFilePath) $Logfile = FileOpen($logFilePath & "\GMS_install" & @MON & "/" & @MDAY & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & ".log",1) FileWriteLine($logFile,@CR & @MON & "/" & @MDAY & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & "_Install_licenses") Consolewrite("Install_licenses" & @CR) Run("C:\Users\factory\Desktop\LicenseInstaller\LicenseInstaller.exe","C:\Users\factory\Desktop\LicenseInstaller") Sleep(1000) WinWait("Gatan License Installer") WinActivate("Gatan License Installer") WinWaitActive("Gatan License Installer") ControlClick("[ACTIVE]","","[NAME:CMD_Install]") Sleep($default_delay) If WinExists("LicenseInstaller") Then WinActivate("LicenseInstaller") WinWaitActive("LicenseInstaller") ControlClick("[ACTIVE]","","[CLASS:Button; INSTANCE:1]") sleep($default_delay) EndIf FileWriteLine($logFile,@CR & @MON & "/" & @MDAY & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & "_Licenses_Installed") Consolewrite("Licenses are installed" & @CR)
  7. This doesn't work, it deletes (overwrites) file contents: $hFile = FileOpen("file.txt", 2) $content1 = FileRead($hFile) $content2 = StringReplace($content1, "old", "new") FileWrite($hFile, $content2) FileClose($hFile) Why? Instead, I have to use this workaround: $hFile = FileOpen("file.txt") $content1 = FileRead($hFile) $content2 = StringReplace($content1, "old", "new") FileClose($hFile) $hFile = FileOpen("file.txt",2) FileWrite($hFile, $content2) FileClose($hFile) That's it, opening, closing and reopening the file. Function reference says: FileWrite. "Write text/data to the end of a previously opened file." (Does it mean "append"?). Remarks: "The file must be opened in write mode or the FileWrite() command will fail." But what write mode? $FO_APPEND (1) = Write mode (append to end of file). $FO_OVERWRITE (2) = Write mode (erase previous contents).
  8. 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!
  9. 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
  10. Hello Good evening, I want to make an inquiry, I have a network file, such as a Word file, a srcipt want me to open it, I can say what the function and an example please.
  11. Hi all. I use a FileOpen command to open a text file ,after that I create a GUI (GUICtrlCreateEdit) and I display the first line from the .txt file with GUICtrlSetData ( controlID, data [, default] ) How can I change the size of what I want to display ?
  12. I want my script write to a log file. I'm using the following code: #include <File.au3> Local $LogFile = FileOpen(@ScriptDir & "logfilename.log", 1) _FileWriteLog($LogFile, "Script started") FileClose($LogFile) The result is as follows: 1. I have an empty file at @ScriptDirlogfilename.log 2. The actual logging is going to a file called "1" in the same directory This seems like it should be so simple - what am I doing wrong? Thanks, Holly
  13. Hi Folks, I have a small GUI application that writes to a text file. This is basically the part of the script: $fh = FileOpen("Test.txt", 9) ;Append at the end of the File and create the dir structure if it doesn't exist FilewriteLine($fh, "Bli bla blubb...") ;Write 1 - many lines to the file FileClose($fh) So ... sometimes while that application is running, there is another file that does something like this: $fh = FileOpen("Test.txt", 2) ;Open file, erase the contents FileClose($fh) Okay, so basically that is bad, because it results in the first script writing several "NULL"s to the file, so if I try to read that file with another script and _FileReadToArray() it basically exits with RC 2 (Unable to split the file). So the question is: Can I detect that the first file is already opened by an application? Maybe I need to mention that the files is stored on a network drive. Any comments are welcome.
  14. Even by reading the Help file I still don't get it when exactly to apply this function, and what happens if I don't use it ? Thanks FileFlush()
  15. Hello all, I created a file .au3 and complete it to .exe and creat a short cut, put in Desktop In original folder .exe had file text.txt, but when i run short cut a file text.txt created in my Desktop. How to it check in original folder had file text.txt? Thank all.
  16. Hi guys, I've been at this for a little while, so I thought I would turn to the community for what should be a simple answer to my problem. I want to write raw data to a file. Now, when I say raw data, I mean I want to write exactly the bytes I want in the file, not the hex equivalant of the characters I send. To be clearer, let me show you me code and explain what's wrong with it: $fOpen = FileOpen(@DesktopDir&"\icons.txt",18) For $d = 15 To 15 For $c = 12 To 12 For $b = 0 To 15 For $a = 0 To 15 $temp = binary(Hex($b, 1) & Hex($a, 1) & Hex($c, 1) & Hex($d, 1)) FileWrite($fOpen,$temp) Next Next Next Next FileClose($fOpen) (I can't post in the code box right now due to a poor internet connection. Sorry guys.) Well I've tried different flags or ways about converting the 4 letter hex code into binary so it will write to the file byte by byte. Nothing has worked so far. To be clear. I'm looking specifically to write raw data to a file; not the data equivalant of the text I am writing. i.e. 4E4F is the equivalant to "NO" in a hex editor. I want to write "4E4F" NOT the Hex equivalant. Thanks before hand for the help guys.
×
×
  • Create New...