Sign in to follow this  
Followers 0
vfaulkner

Easy question from a beginer

13 posts in this topic

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!

Share this post


Link to post
Share on other sites




,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#6 ·  Posted (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 by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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.

@water

You meant

Many 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!"

Share this post


Link to post
Share on other sites

@GeoSoft

Sure, I meant FileReadLine :D


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#9 ·  Posted (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 by vfaulkner

Share this post


Link to post
Share on other sites

#10 ·  Posted (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 by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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!"

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

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