Sign in to follow this  
Followers 0
Lakes

Fileopen Mode

6 posts in this topic

I`m having trouble understanding this.

Mode 2, I understand, it writes the file to which ever Dir the Script is run from.

This is the part I`m having trouble with..

None existing directory structure:

------------------------------------

By default the file will not be created if the directory structure doesn't exist.

To overwrite this behaviour use the modes '1' and '2' together with mode-flag '8'!

For instance the mode-flag '9' (1 + 8) checks for the directory structure and if it doesn't exist creates it automatically and then opens the file for appending.

Ok, what structure does it create and where?

When I tried mode 9 or 10, I get the error 'Unable to Open File'

Thanks!


2015 - Still no flying cars, instead blankets with sleeves.

Share this post


Link to post
Share on other sites



Hi,

what do you want to do?

Create file if directory structure not exist?

The number depends on what should happen. :)

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

I`m having trouble understanding this.

Mode 2, I understand, it writes the file to which ever Dir the Script is run from.

This is the part I`m having trouble with..

None existing directory structure:

------------------------------------

By default the file will not be created if the directory structure doesn't exist.

To overwrite this behaviour use the modes '1' and '2' together with mode-flag '8'!

For instance the mode-flag '9' (1 + 8) checks for the directory structure and if it doesn't exist creates it automatically and then opens the file for appending.

Ok, what structure does it create and where?

When I tried mode 9 or 10, I get the error 'Unable to Open File'

Thanks!

Hard to see your problem with only abstract discussion. Could you post a code sample of what doesn't work?

For example, the following should work, creating the path and the file at the same time, writing to it, closing it, then displaying it in notepad:

$FilePath = "C:\Temp\NewFolder\NewFile.txt"
$FileHandle = FileOpen($FilePath, 8+1); Mode = create path + append
FileWriteLine($FileHandle, "New text")
FileClose($FileHandle)
RunWait("notepad " & $FilePath)

Hope that helps. :)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Ok heres the code I been experimenting with to get around the Edit Box buffer limit.

#include <GUIConstants.au3>

; == GUI generated with Koda ==);

$TestEditBox = GUICreate("Test Edit Box", 405, 507, 190, 153)
$Testedit = GUICtrlCreateEdit("", 8, 8, 386, 457, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_GROUP,$WS_HSCROLL,$WS_VSCROLL))

$CurrLine = GUICtrlCreateLabel("Current Line", 8, 480, 377, 17, $WS_GROUP)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")


GUISetState(@SW_SHOW)

$Count = 0
$String = "The Quick Brown Fox Jumped Over the Lazy Moon"
$NotePad = "Untitled - Notepad"
$NPad = "Edit1"
$CR = ASC(13)
$LF = ASC(10)

Run("notepad.exe")

GUISetState(@SW_SHOW)

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


$LogText =FileOpen("LogText.txt", 1);<----------- Changing this to 8 or 10 causes the error loop to activate.
If $LogText = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf


 For $i = 1 to 50
    $Line = ControlCommand($TestEditBox, "", $TestEdit,"GetLineCount", "")
    If $Line = 500 then GUICtrlSetData ( $TestEdit, "Reset")
    $Output = StringStripCR ($i &" " &$String);<<<-----
    ControlFocus ( $TestEditBox, "", $TestEdit )
    ControlCommand($TestEditBox, "", $TestEdit, "EditPaste", $Output)
    ControlSend($TestEditBox, "", $TestEdit, "{ENTER}")
    ControlCommand($NotePad, "", $NPad, "EditPaste", $Output)
    ControlSend($NotePad, "", $NPad, "{ENTER}")
    GUICtrlSetData ($CurrLine, $i)
            FileWriteLine ($Log, $String)
            FileWriteLine ($LogText, $Output)

 Next   

While 1
 $msg = GUIGetMsg()
   Select
      Case $msg = $GUI_EVENT_CLOSE
        GUIDelete()
    FileClose ($Log)
    FileClose ($LogText)
         Exit
   EndSelect

WEnd

Exit

The script works fine as as far I as want it to, I just don`t understand when I change this line:

$LogText =FileOpen("LogText.txt", 1) to 8 or 10 it causes the error loop to activate...

If I leave it as it is it works fine.


2015 - Still no flying cars, instead blankets with sleeves.

Share this post


Link to post
Share on other sites

Ok heres the code I been experimenting with to get around the Edit Box buffer limit.

#include <GUIConstants.au3>

; == GUI generated with Koda ==);

$TestEditBox = GUICreate("Test Edit Box", 405, 507, 190, 153)
$Testedit = GUICtrlCreateEdit("", 8, 8, 386, 457, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_GROUP,$WS_HSCROLL,$WS_VSCROLL))

$CurrLine = GUICtrlCreateLabel("Current Line", 8, 480, 377, 17, $WS_GROUP)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)

$Count = 0
$String = "The Quick Brown Fox Jumped Over the Lazy Moon"
$NotePad = "Untitled - Notepad"
$NPad = "Edit1"
$CR = ASC(13)
$LF = ASC(10)

Run("notepad.exe")

GUISetState(@SW_SHOW)

 $Log =FileOpen("Log.txt", 1)
 If $Log = -1 Then
     MsgBox(0, "Error", "Unable to open file.")
     Exit
 EndIf
$LogText =FileOpen("LogText.txt", 1);<----------- Changing this to 8 or 10 causes the error loop to activate.
If $LogText = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf
 For $i = 1 to 50
    $Line = ControlCommand($TestEditBox, "", $TestEdit,"GetLineCount", "")
    If $Line = 500 then GUICtrlSetData ( $TestEdit, "Reset")
    $Output = StringStripCR ($i &" " &$String);<<<-----
    ControlFocus ( $TestEditBox, "", $TestEdit )
    ControlCommand($TestEditBox, "", $TestEdit, "EditPaste", $Output)
    ControlSend($TestEditBox, "", $TestEdit, "{ENTER}")
    ControlCommand($NotePad, "", $NPad, "EditPaste", $Output)
    ControlSend($NotePad, "", $NPad, "{ENTER}")
    GUICtrlSetData ($CurrLine, $i)
            FileWriteLine ($Log, $String)
            FileWriteLine ($LogText, $Output)

 Next   

While 1
 $msg = GUIGetMsg()
   Select
      Case $msg = $GUI_EVENT_CLOSE
        GUIDelete()
    FileClose ($Log)
    FileClose ($LogText)
         Exit
   EndSelect

WEnd

Exit

The script works fine as as far I as want it to, I just don`t understand when I change this line:

$LogText =FileOpen("LogText.txt", 1) to 8 or 10 it causes the error loop to activate...

If I leave it as it is it works fine.

Because you are asking it to create a path that you are not specifying. You have to specify the folder you want to create. See PsaltyDS's example and notice the path and file name.

Share this post


Link to post
Share on other sites

Because you are asking it to create a path that you are not specifying. You have to specify the folder you want to create. See PsaltyDS's example and notice the path and file name.

Ah!, I see!

Thanks, I understand now! :)


2015 - Still no flying cars, instead blankets with sleeves.

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