Sign in to follow this  
Followers 0
blackmage999

_FileCreate problem

3 posts in this topic

#1 ·  Posted (edited)

#Include <File.au3>

$PlayerName = ClipGet()

;;;;;open credit file or create new

If FileExists(@DesktopDir & "\PlayerCredits\" + $PlayerName & ".txt") Then

$PlayerCreditFile = FileOpen(@DesktopDir & "\PlayerCredits\" + $PlayerName & ".txt", 0)

Else

_FileCreate(@DesktopDir & "\PlayerCredits\" + $PlayerName & ".txt")

$PlayerCreditFile = FileOpen(@DesktopDir & "\PlayerCredits\" + $PlayerName & ".txt", 0)

EndIf

;;;;;get player credits

$PlayerCredit = FileReadLine($PlayerCreditFile)

FileClose($PlayerCreditFile)

Im using this code in one of my scripts, but it fails to create a .txt. any help on what the problem might be would be appricated

Edit: I just relized i used +'s instead of &'s...fixed, but still fails to create my .txt

Edited by blackmage999

Share this post


Link to post
Share on other sites



Try this.

$PlayerCreditFile = FileOpen(@DesktopDir & "\PlayerCredits\" & $PlayerName & ".txt", 9)

and read about the mode option for fileopen() in the help file


"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites

Evidently _FileCreate cannot create a new directory. This works

#include <File.au3>

$PlayerName = ClipGet()

;;;;;open credit file or create new
If FileExists(@DesktopDir & "\PlayerCredits\" & $PlayerName & ".txt") Then
    $PlayerCreditFile = FileOpen(@DesktopDir & "\PlayerCredits\" & $PlayerName & ".txt", 0)
Else
    If Not FileExists(@DesktopDir & "\PlayerCredits") Then DirCreate(@DesktopDir & "\PlayerCredits")
    If Not _FileCreate(@DesktopDir & "\PlayerCredits\" & $PlayerName & ".txt") Then
        MsgBox(4096, @DesktopDir & "\PlayerCredits\" & $PlayerName & ".txt", " Error Creating/Resetting log.      error:" & @error & @LF & @DesktopDir & "\PlayerCredits\" & $PlayerName & ".txt")
        Exit
    EndIf
    $PlayerCreditFile = FileOpen(@DesktopDir & "\PlayerCredits\" & $PlayerName & ".txt", 0)
EndIf

;;;;;get player credits
$PlayerCredit = FileReadLine($PlayerCreditFile)
FileClose($PlayerCreditFile)

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