Jump to content
Sign in to follow this  
fRequEnCy

Problems with _FileWriteLog & FileOpen after update

Recommended Posts

fRequEnCy

Hello all. Forgive my ignorance. I was working on a script and all was working fine and then decided to update to current version to apply logging of new OS (Win 7). Well to my surprise my script no longer logs. So I did a basic script for testing and sure enough I can't get it to work.

Here is test script:

#include <File.au3>

if Not FileExists(@ScriptDir & "\log.txt") Then
    _FileCreate(@ScriptDir & "\log.txt")
EndIf

FileOpen(@ScriptDir & "\log.txt", 2)
_FileWriteLog(@ScriptDir & "\log.txt", "testing 1")
_FileWriteLog(@ScriptDir & "\log.txt", "testing 2")

According to help file:

Return Value

Success: Returns a file "handle" for use with subsequent file functions.

Failure: Returns -1 if error occurs.

So I tested with a message box and gave FileOpen a variable and it returned a 1. So maybe this is where I'm having issues?

I also did a full uninstall and reinstall to make sure I didn't do something wrong in the upgrade. Any help is appreciated.

Share this post


Link to post
Share on other sites
water

I think you mix up two things.

Fileopen returns a handle. But if you never use the handle in your script then this is not needed.

_FileWriteLog doesn't use a handle. So it opens the file, writes the text and closes the file.

Thus having said I would change your script to:

#include <File.au3>
_FileWriteLog(@ScriptDir & "\log.txt", "testing 1")
_FileWriteLog(@ScriptDir & "\log.txt", "testing 2")

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
fRequEnCy

I think you mix up two things.

Fileopen returns a handle. But if you never use the handle in your script then this is not needed.

_FileWriteLog doesn't use a handle. So it opens the file, writes the text and closes the file.

Thus having said I would change your script to:

#include <File.au3>
_FileWriteLog(@ScriptDir & "\log.txt", "testing 1")
_FileWriteLog(@ScriptDir & "\log.txt", "testing 2")

That worked great! Thanks for the tip. Creates the file and all so no need for all that extra junk. Another question that I now have is how do I clear the contents in the beginning so that it creates a new log everytime? That's why I thought I had to use FileOpen with mode 2 to erase the previous contents.

Share this post


Link to post
Share on other sites
water

Just delete the file with FileDelete.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
fRequEnCy

Just delete the file with FileDelete.

LOL. Well that makes sense and is an easy solution. Many thanks for your quick responses and help. Now I can move forward with my script. Just weird that it worked before the update. But no matter since was going about it all wrong anyways. :D

Share this post


Link to post
Share on other sites
water

There have been some changes in the latest versions of AutoIt regarding file handling. All changes (including script breaking changes) are documented here.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.