Jump to content
Sign in to follow this  

Why I got errors when trying to delete a character from a file?

Recommended Posts



This is my first post on this forum. I've just installed Autoit and try to do some useful work ;)

Here is my problem. I got a text file "names.txt" with 1000 names and surnames. The file looks like this:

Adam Smith

Bryan Brown

Cecil Alden

...... and the following 1000 names like these.

What I need to do is to put all these 1000 names and surnames into a right box. Apart from this I have to create an email address out of each name and surname. An address should look like this: 


So basically what I need to do is to remove the space character from between a name and a surname and add to the end of this string a constant string "@blablabla.com".

I need to do just these two things. And I got still errors. Can you please check my code and tell me why?

#include <File.au3>

Const password = "blablabla1"
Const email_suffix = "@blablabla.com"
$file = "C:\Users\monique #1\Desktop\names.txt"
$file2 = "C:\Users\monique #1\Desktop\email.txt"
$name = ""
$email = ""

;Step 0. The general loop
Local $i = 1
While $i <= 1000

;Step 1. Open a file, read a line and copy it to the "$name" variable
FileOpen($file, 0)
$name = FileReadLine($file, $i+1)

;The "$name" variable should be now the first username (name and surname) from the file

;Step 2. Create an email address for a given username
FileOpen($file2, 1)
$email = FileWriteLine($file2, $name-"", $email_suffix)

;The "$email" variable should look now as the following: namesurname@blablabla.com
;which means the "name" and "surname" without a space character
;Step 3. Here goes the code which inserts variables: $name, $email and $password 
; to the correct boxes and the loop may run again. I got this code and it works!

So why I got errors? This is an easy code I guess and I still can't do it properly. Would be grateful for your suggestions.


Share this post

Link to post
Share on other sites

What is the purpose of creating so much email addresses?



Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post

Link to post
Share on other sites

What is the purpose of creating so much email addresses?




It's all for a blog project. We (me and my friends) want our blog to have at least 1000 users so we have to create them :) So we have created user names and one password and an email address in the same domain for every user. We don't want to do this manually that is why I found out about Autoit, downloaded it and decided to learn it :)

Share this post

Link to post
Share on other sites

The good thing about autoit is the help file is actually... helpful!

This is a bit more complicated than it has to be, but it will give you a decent starting point into how to use autoit for other more complex things. There are definitely easier ways (actually with only a few lines)

$LoadFile = "C:\NameList.txt" ; set the path to your file here
$SaveFile = "C:\EmailList.txt"
$Domain = "@blablabla.com" ; set the text to append to the end of the names

$ArrNames = StringSplit(FileRead($LoadFile),@CRLF,1) ; this splits the text in the file into an array using a "return" keystroke as the splitter
Local $WriteData ; declare a variable to use to store the prepared data
for $i = 1 to $ArrNames[0] ; do the following code for each line in the file
    $WriteData &= StringStripWS($ArrNames[$i],8) & $Domain & @CRLF ; strips the part of the string read from the file (name) of all space characters, 
                                                                   ; adds the domain and a "return". appends this data to the end of $WriteData
next ; loops back to "for"

$hWriteFile = FileOpen($SaveFile,2) ; prepares a new file to be written
FileWrite($hWriteFile,$WriteData) ; write the data you've assembled to the new file
FileClose($hWriteFile) ; close the file since we're done writing

msgbox(0,"Complete","Operation has completed.") ; show a message box saying the operation completed successfully.

If there's anything that doesn't make sense, look at the help file and look up the function for detailed information on how to use it along with examples.

Edited by FlashpointBlack

Share this post

Link to post
Share on other sites

Thank you very much. I used your code, change it slightly and expanded. Now it works perfect. Thanks again.

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