Sign in to follow this  
Followers 0
MSF

Reading/Writing text

6 posts in this topic

Using AutoIT; is it possible to read in a large text file and append an asterisk to the end of each record in the text file? Each record is terminated by a carriage return and line feed.

Share this post


Link to post
Share on other sites



FileReadLine along with _FileWriteToLine

Share this post


Link to post
Share on other sites

FileReadLine along with _FileWriteToLine

It's that easy? Man I love AutoIT! :)

Share this post


Link to post
Share on other sites

This is probably faster.

#include <File.au3>

Global $aArray
Global $sFilePath = "C:\temp\test.txt"

_FileReadToArray($sFilePath, $aArray)
If @error Then
    ConsoleWrite("Error reading file." & @CR)
    Exit
EndIf

For $i = 0 To $aArray[0]
    $aArray[$i] &= "*"
Next

_FileWriteFromArray($sFilePath, $aArray, 1)
If @error Then
    ConsoleWrite("Error writing file from array." & @CR)
EndIf

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

This is probably faster.

#include <File.au3>

Global $aArray
Global $sFilePath = "C:\temp\test.txt"

_FileReadToArray($sFilePath, $aArray)
If @error Then
    ConsoleWrite("Error reading file." & @CR)
    Exit
EndIf

For $i = 0 To $aArray[0]
    $aArray[$i] &= "*"
Next

_FileWriteFromArray($sFilePath, $aArray, 1)
If @error Then
    ConsoleWrite("Error writing file from array." & @CR)
EndIf
Thanks!

Also,

These records are actually customer id's. I have a directory full of .tiff's that are named by the customer ID. How can I take all these newly edited records with the * append and put them on the same line? I would like to use this new long string of file names to write a dos batch file. I'm trying to write a dos batch script that takes ton of files and moves them to another directory. ie

move 12345*.tiff, 123456*.tiff, 1234567*.tiff \newDirectory

But if I can do all this without a dos batch script that would be cool!

P.S.

I would RTFM but I'm under a serious time crunch here. Sorry.

Edited by MSF

Share this post


Link to post
Share on other sites

Hm... Perhaps I could strip all the carriage return and line feeds from the array before writing to the file

#include <File.au3>

Global $aArray
Global $sFilePath = "C:\temp\test.txt"

_FileReadToArray($sFilePath, $aArray)
If @error Then
    ConsoleWrite("Error reading file." & @CR)
    Exit
EndIf

For $i = 0 To $aArray[0]
    $aArray[$i] &= "*, "
    ; could I strip the @cr and @lf here?
Next

   ; or should I strip all @cr and @lf's from $aArray?
_FileWriteFromArray($sFilePath, $aArray, 1)
If @error Then
    ConsoleWrite("Error writing file from array." & @CR)
EndIf

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