Jump to content

Reading/Writing text


Recommended Posts

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.

Link to comment
Share on other sites

  • Moderators

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
Link to comment
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
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
Link to comment
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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...