vfaulkner Posted November 1, 2011 Posted November 1, 2011 Hello, I am new to Autoit Script and coding in general, and would like to use it to streamline some repetitive work. Here is what I need the script to do: 1. Open a .txt file (Event Creator.txt) from my desktop (C:\Users\VFaulkner\Desktop) 2. Copy lines 2,4,6, and so on from that text 3. Paste those lines into the appropriate points of another .txt file (Event HTML.txt) also from my desktop (C:\Users\VFaulkner\Desktop) My job requires that I create standard webpages for different events. This seems to me to be a way to paste the different fields into the appropriate places of html code which I can then just copy and paste on our website. Any help would be appreciated!
iamtheky Posted November 1, 2011 Posted November 1, 2011 id go with learning these: FileOpen FileRead FileReadLine FileWrite FileWriteLine FileClose ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
vfaulkner Posted November 1, 2011 Author Posted November 1, 2011 Thanks. Would this be the proper syntax for the first two? FileOpen("Event Creator.txt", 0) FileRead ( "Event Creator.txt" ) When I run this it does not appear to start notepad or open the right file. Sorry--I'm new to all of this.
iamtheky Posted November 1, 2011 Posted November 1, 2011 (edited) that would if the file were relative, and take a look at fileread closely: you have options to use the handle from your fileopen or the full path of the filename. one or the other may be more suitable depending on your needs. $handle = FileOpen ("The whole path and filename" , 0) $Read = FileRead ($handle) msgbox (0, '' , $Read) Edited November 1, 2011 by boththose ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
somdcomputerguy Posted November 1, 2011 Posted November 1, 2011 There is examples in the Help file for all the AutoIt functions. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change.
water Posted November 1, 2011 Posted November 1, 2011 (edited) It depends on the size of the file. Many single FileRead calls slow down your script. If the file isn't too large you could do a _FileReadToArray to read the whole file into an array. Then loop through the array and select those lines you want to write to a new file. Something like: $aFileRead = _FileReadToArray("C:\Users\VFaulkner\Desktop") ; Read the whole file into an array $hFileWrite = FileOpen("C:\Users\VFaulkner\Desktop\Event HTML.txt", 1) ; Open the output file in append mode For $i = 2 to $aFileRead[0] Step 2 ; Take every second line and write it to the output file FileWrite($hFileWrite, $aFileRead[$i]) Next FileClose($hFileWrite) ; close the output file What is still missing is some error checking. Do all files exist? Does the input file have at least 2 lines? Edited November 1, 2011 by water My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
GEOSoft Posted November 1, 2011 Posted November 1, 2011 Is there something common to the text of the lines you are attempting to read? I'm pretty sure you don't want to just read every second line of text. @waterYou meantMany single FileReadLine calls slow down your script.did you not? FileReadLine() is the slowest possible method there is to read the data from a file whereas FileRead() is quite fast since you only read that file one time, retrieve the data and then either close the file or write the changed data back to it one time. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
water Posted November 1, 2011 Posted November 1, 2011 @GeoSoft Sure, I meant FileReadLine My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
vfaulkner Posted November 1, 2011 Author Posted November 1, 2011 (edited) Still having trouble getting notepad to open the file. Here are the first 2 lines: ; Script Start - Add your code below here FileOpen("C:\Users\VFaulkner\Desktop\Event Creator.txt", 0) When I run it nothing appears to happen. Shouldn't I see notepad open with the file? Edited November 1, 2011 by vfaulkner
water Posted November 1, 2011 Posted November 1, 2011 (edited) FileOpen does nothing "visible". It opens the files for later read or write operations and just returns a handle to the opened file. This handle has to be used by FileRead/FileWrite. Edited November 1, 2011 by water My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
GEOSoft Posted November 1, 2011 Posted November 1, 2011 If you want to actually see the file contents using the default text editor just use ShellExecute() ShellExecute("C:\Users\VFaulkner\Desktop\Event Creator.txt") George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
vfaulkner Posted November 5, 2011 Author Posted November 5, 2011 How can I make a line of text a variable? As @GEOSoft said, I am not going to copy every 2nd line; rather I want to copy line 2, line 4, and line 6. Thus I want to open a file: $event_creator = FileOpen("C:\Users\VFaulkner\Desktop\Event Creator.txt", 0) Read that file: FileReadLine( "$event_creator" , 2) Then turn lines 2, 4, and 6 into a variable (this part I don't know how to do) and insert them into a new document: $new_html = FileOpen("C:\Users\VFaulkner\Desktop\Event HTML.txt", 1) ; Check if file opened for writing OK If $new_html = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf FileWrite($new_html, "$Line_2") FileWrite($new_html, "$Line_4") FileWrite($new_html, "$Line_6") Thanks
martin Posted November 5, 2011 Posted November 5, 2011 You need to spend some time with the help, reading the examples and trying them out. The help has answers to all your questions. You need to learn the basics of how to use AutoIt and since you appear to have no programming experience, it will take some time. There are lots of people here who will help with different aspects but at the moment you want to be told how to do something instead of learning how to do it. Search for tutorials etc. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now