Glad that the script worked. You are welcome.
Now let me explain a bit and then you can see if you can write the ".fm" one.
;AutoIt Version: 3.3.8.1
Using a ";" allows you to add comments to the code, In this case, it just states the AutoIt version that the code was written for. As versions change, some code may no longer work. But this is not a problem since you have the compiled file to use. You can also download old versions if need be - or never update your current version.
$search = FileFindFirstFile("*.txt")
This line puts info in the the variable named $search so that files in a folder can be found based on the filter of "*.txt".
If $search = -1 Then
MsgBox(0, "Error", "No files/directories matched the search pattern")
FileClose($search)
Exit
EndIf
This part lets you know if no files matched the filter.
While 1
This starts an infinite loop.
$file = FileFindNextFile($search)
Even though the function includes the words find and next, the first time this is encountered, it will be dealing with the very first file in the list of files that we are working with. The variable named $file contains info needed to work with a file.
If @error Then ExitLoop
Once there are no more files to work with, it is time to exit the infinite loop.
$whole_file = FileRead($file)
The contents of the file we are currently working with is read and put into the variable named $whole_file.
$file_handle = FileOpen($file, 2)
Reading the file (like we did in the previous line of code) does not require that we "open it". Once we open a file, we lock it so that no other process can make changes to it until we close the file. If you look in the help file under FileOpen, you will see what the "2" in ($file, 2) does. This is why your script created a blank file. We want to remove the current contents of the file so that we can write the new contents.
BTW, if you right click on the "au3" script file, one of the context menu options should be to edit the script. Selecting that option should open the customized editor. Click on or arrow over to a function like FileOpen and then press F1. The editor will take note of the function that you are on and will open the help file to the info for that function.
$new_file_info = ""
This is the variable that is going to hold the info that goes into the new file. We want it to start off empty too. A real programmer would create this variable a different way and probably in a different place in the script. I'm just self taught and I like to create them closer to where I use them. I find that easier to read.
$sentence_array = StringSplit($whole_file, @CRLF, 1)
This takes the info in the variable named $whole_file and splits it into lines.
$sentence_array[0] = the number of lines in the array
$sentence_array[1] = the first line of info from the file that we are currently working with
$sentence_array[2] = the second line of info from the file
......
For $i = 1 To $sentence_array[0]
Now we want to loop thru each of the lines from the file
$word_array = StringSplit($sentence_array[$i], " ", 1)
This splits each line into individual words
$word_array[0] = the number of words in the current line
$word_array[1] = the first word
$word_array[2] = the second word
.....
For your ".fm" script, you will want to split the "words" using a comma instead of a space.
$word_array = StringSplit($sentence_array[$i], ",", 1)
For $ii = 1 To $word_array[0]
Now we want to loop thru each of the words from the line that we are working on
If $word_array[$ii] = "and" Then $word_array[$ii] = "&"
If the word that we are working with = and - then replace it with &
This is the area of the script that you will want to modify in order to write the ".fm" script. I'm not positive, but maybe something like:
If $ii = 1 Then $word_array[$ii] &= ".fm"
That would be saying:
If we are working with the first word in the line, replace it with itself plus .fm
This next block of code is was added after I saw flaws in the output file.
I need to explain them out of order, so here is the block and below it is some info about the code
...................
If $ii = $word_array[0] Then
If $i = $sentence_array[0] Then
$new_file_info &= $word_array[$ii]
Else
$new_file_info &= $word_array[$ii] & @CRLF
EndIf
Else
$new_file_info &= $word_array[$ii] & " "
EndIf
...................
For your ".fm" script, you will want to change this line
$new_file_info &= $word_array[$ii] & " "
to
$new_file_info &= $word_array[$ii] & ","
Now back to explaining the script....
$new_file_info &= $word_array[$ii]
Originally, I had that one line of code instead of the block of code that you see above.
Remember that $new_file_info starts out empty. The line of code above appends the first word of the first line to the variable named $new_file_info as we rebuild the file. As the loops continue, each word from the file being worked on is added to the end of the variable named $new_file_info. Maybe you already see the problem. The words came out all crammed together - without a space between each word.
So, the code was changed to add a space after each word.
$new_file_info &= $word_array[$ii] & " "
But that also created a problem.
If the original file looked like this:
We were stranded and had to walk.
The new file would look like this:
We were stranded & had to walk. <there would be an extra space at the end
So, I had to add a condition like this:
If $ii = $word_array[0] Then
If the loop was working on the last word in a line, then do not put the space after it.
The same is true for the last line of the file. I don't want a carriage return line feed added after the last line of the new file; so, this condition was added:
If $i = $sentence_array[0] Then
I cannot explain that block of code much better than that - but the good news is, you don't have to change much if that code for your ".fm" script.
Next
This lets us work on the next word in a line until the line is finished.
Next
This lets us work on the next line in the file until the file is finished.
FileWrite($file_handle, $new_file_info)
This writes the new info to the empty file.
FileClose($file_handle)
This closes and unlocks the file that we just wrote to.
WEnd
This send the script back to the While line of code so that we can find and work with the next file.
FileClose($search)
After all files have been worked on, end the search.
MsgBox(0, "AutoIt", "Finished!")
Let the human know that the script has completed.
You've not wasted any of my time and my time is not all that valuable
