Jump to content

ADD A SPACE IN A TXT FILE


Recommended Posts

$file = FileOpen("test.txt", 0)
$file2 = FileOpen("test2.txt", 2)

If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

If $file2 = -1 Then
    MsgBox(0, "Error", "Unable to open file2.")
    Exit
EndIf

While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
    
;~     MsgBox(0, "Line original:", $line)
    $line = StringSplit($line,'')
    $line2 = ''
    For $i = 1 To $line[0]
        $line2 &= $line[$i] & ' '
    Next
    
;~     MsgBox(0, "Line with spaces:", $line2)
    FileWriteLine($file2, $line2)
Wend

FileClose($file)
FileClose($file2)

EDIT: As start was used example from AutoIt Helpfile for function FileReadLine.

Edited by Zedna
Link to comment
Share on other sites

  • Developers

$text = "mother"
$Ntext = ""
For $x = 1 To StringLen($text) -1 
    $Ntext &= StringMid($text,$x,1) & " "
Next
$NText &= StringMid($text,$x)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

[autoit]$file = FileOpen("test.txt", 0)

$file2 = FileOpen("test2.txt", 2)

If $file = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

If $file2 = -1 Then

MsgBox(0, "Error", "Unable to open file2.")

Exit

EndIf

.......

Am I right to assume that Exit closes all open files?

Or do I need to close all files explicitly?

Bart

Link to comment
Share on other sites

Am I right to assume that Exit closes all open files?

Or do I need to close all files explicitly?

Bart

Check the helpfile... :D

Remarks

If filehandle is invalid, an AutoIt runtime error will be thrown, and the script will terminate!

Upon termination, AutoIt automatically closes any files it opened--but calling FileClose is still a good idea.

This function is also used to close search handles as returned by FileFindFirstFile().

Link to comment
Share on other sites

Check the helpfile... :D

Ok, so I should explicitly close any open files, but how can I check if a file is open?

When error handling it's not always certain the error occured after the file was opened!

And there is a runtime error when I try to close a file that is not open.

Bart

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...