Jump to content

why does _FileWriteToLine not work


Recommended Posts

some how this does not work any one know why ?

#include <File.au3>

Global $sIniFile = FileOpen(@ScriptDir & "test.txt", 0)
;Example: Write to line 3 of c:\test.txt REPLACING line 3
_FileWriteToLine($sIniFile, 3, "my replacement for line 3", 1)
;Example: Write to line 3 of c:\test.txt NOT REPLACING line 3
_FileWriteToLine($sIniFile, 3, "my insertion", 0)
Edited by Merchants
Link to comment
Share on other sites

some how this does not work any one know why ?

#include <File.au3>

Global $sIniFile = FileOpen(@ScriptDir & "test.txt", 0)
;Example: Write to line 3 of c:\test.txt REPLACING line 3
_FileWriteToLine($sIniFile, 3, "my replacement for line 3", 1)
;Example: Write to line 3 of c:\test.txt NOT REPLACING line 3
_FileWriteToLine($sIniFile, 3, "my insertion", 0)

Try putting a path in there.

Untested:

#include <File.au3>

Global $sIniFile = FileOpen(@ScriptDir & "test.txt", 0)
;Example: Write to line 3 of c:\test.txt REPLACING line 3
_FileWriteToLine(@ScriptDir & "/" & $sIniFile, 3, "my replacement for line 3", 1)
;Example: Write to line 3 of c:\test.txt NOT REPLACING line 3
_FileWriteToLine(@ScriptDir & "/" & $sIniFile, 3, "my insertion", 0)

Some guy's script + some other guy's script = my script!

Link to comment
Share on other sites

some how this does not work any one know why ?

#include <File.au3>

Global $sIniFile = FileOpen(@ScriptDir & "test.txt", 0)
;Example: Write to line 3 of c:\test.txt REPLACING line 3
_FileWriteToLine($sIniFile, 3, "my replacement for line 3", 1)
;Example: Write to line 3 of c:\test.txt NOT REPLACING line 3
_FileWriteToLine($sIniFile, 3, "my insertion", 0)

If you were just using FileWrite() or FileWriteLine()...

In your FileOpen, your flag is 0 which means open the file in read-only mode. You need to use one of the write modes, check help file for reference.

Also, @ScriptDir doesn't include a trailing backslash \ so you'll need to add one prior to "test.txt".

But since you're using _FileWriteToLine() you would need to specify a hard path for the first parameter like Werty said, so just replace your Global $sIniFile line to:

Global $sIniFile = @ScriptDir & "\text.txt"

It would be more efficient to assign the file path to your $sIniFile variable then continue to use $sIniFile instead of the actual path every time you use the _FileWriteToLine function.

Link to comment
Share on other sites

Try this:

#include <File.au3>
Global $sIniFile = FileOpen(@ScriptDir & "\test.txt",2)
;=== some lines of text to test:
For $i=1 To 10
FileWriteLine($sIniFile,"This is line "&$i)
Next
FileClose($sIniFile)
;=== now your code:
;Example: Write to line 3 of c:\test.txt REPLACING line 3
_FileWriteToLine(@ScriptDir & "\test.txt", 3, "my replacement for line 3", 1)
;Example: Write to line 3 of c:\test.txt NOT REPLACING line 3
_FileWriteToLine(@ScriptDir & "\test.txt", 3, "my insertion", 0)
Link to comment
Share on other sites

#include <File.au3> 
Global $sIniFile = @ScriptDir & "\test.txt"
;Example: Write to line 3 of c:\test.txt REPLACING line 3 
_FileWriteToLine($sIniFile, 3, "my replacement for line 3", 1) 
;Example: Write to line 3 of c:\test.txt NOT REPLACING line 3 
_FileWriteToLine($sIniFile, 3, "my insertion", 0)

Br,

UEZ

Edited by UEZ

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Merchants, in your first script you have to pass the file (with path) to the _FileWriteToLine function, not the file handle.

Second, the file must exists - see the @Error in case of failure (that's why I wrote a test file in the begining).

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