Jump to content
Sign in to follow this  
Wolfx128

FileOpenDialog and Dir

Recommended Posts

Wolfx128

I wam writing a program to let me change settings for my other program.

When I open a file with the FileOpenDialog Method I am completely change my save directory, yet I don't want to have to go through the hassel of makeing a FileSaveDialog to let me choose where to save it since I just want it to save to my current Dir.

Is there something I should do to keep me at my current dir, to find my current dir, or set my file to save at my current dir?

Func FindFile( $Target, $Title )
    $Found = FileOpenDialog( $Title, $Loc, "XML (*.xml)")
    If Not StringCompare($Found,"") = 0 Then
        $Found = StringTrimLeft($Found, StringInStr($Found, "\", 0 , -1))
        GUICtrlSetData( $Target, $Found )
    EndIf
EndFunc

The part include the FileOpenDialog.

Share this post


Link to post
Share on other sites
DW1

Not sure if I know exactly what you mean, but something along the lines of this?

If Not FileExists( @TempDir & "\test.txt" ) Then
    MsgBox(0, "test", "Test file not found... creating it at: " & @TempDir & "\test.txt")
    FileWrite( @TempDir & "\test.txt", 'setting1 = 0' & @CRLF & 'setting2 = 0')
EndIf

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 378, 215, 193, 125)
$Edit1 = GUICtrlCreateEdit("", 8, 8, 361, 169)
GUICtrlSetData(-1, "Edit1")
$Button1 = GUICtrlCreateButton("Save File", 104, 184, 161, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

$file = FileOpenDialog('Choose a file to open', @TempDir, "test file (test.txt)", 1, 'test.txt', $Form1 )
If @error Then 
    MsgBox(0, "error", "FileOpenDialog error")
    Exit
EndIf
$FileData = FileRead( $file )
GUICtrlSetData( $Edit1, $FileData )

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            FileDelete( $file )
            FileWrite( $file, GUICtrlRead( $Edit1 ))
            MsgBox(0, "Test", "Settings changed." & @CRLF & "Click OK to reload file.")
            $FileData = FileRead( $file )
            GUICtrlSetData( $Edit1, $FileData )
    EndSwitch
WEnd

Share this post


Link to post
Share on other sites
Wolfx128

Ok I think I may have messed up what I was saying...

But you have the general Idea. I am trying to make my file write to the same directory my program is running in. But I am loading an .XML from another folder.

When I load the .XML it changes my directory to save my "Setup.ini" in the same directory as my ".xml" not in the location of my program.

Share this post


Link to post
Share on other sites
enaiman

@ScriptDir = folder where your running script is located

... I am completely confused ... what are you trying to do??


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites
DW1

Then I guess this would be a demonstration of what I think you are asking:

If Not FileExists( @TempDir & "\test.txt" ) Then
    MsgBox(0, "test", "Test file not found... creating it at: " & @TempDir & "\test.txt")
    FileWrite( @TempDir & "\test.txt", 'setting1 = 0' & @CRLF & 'setting2 = 0')
EndIf

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 378, 215, 193, 125)
$Edit1 = GUICtrlCreateEdit("", 8, 8, 361, 169)
GUICtrlSetData(-1, "Edit1")
$Button1 = GUICtrlCreateButton("Save File", 104, 184, 161, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

$file = FileOpenDialog('Open the test file...', @TempDir, "test file (test.txt)", 1, 'test.txt', $Form1 )
$ss = StringSplit( $file, "\" )
$FileName = $ss[$ss[0]] ; Full new location with old filename = @ScriptDir & "\" & $FileName

If @error Then 
    MsgBox(0, "error", "FileOpenDialog error")
    Exit
EndIf
$FileData = FileRead( $file )
GUICtrlSetData( $Edit1, $FileData )

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            If FileExists( @ScriptDir & "\" & $FileName ) Then FileDelete( @ScriptDir & "\" & $FileName )
            FileWrite( @ScriptDir & "\" & $FileName, GUICtrlRead( $Edit1 ))
            MsgBox(0, "Test", "Settings changed." & @CRLF & @CRLF & "Click OK to reload file from new location:" & @CRLF & '(@ScriptDir & "\" & $FileName)' & @CRLF & @ScriptDir & "\" & $FileName)
            $FileData = FileRead( @ScriptDir & "\" & $FileName )
            GUICtrlSetData( $Edit1, $FileData )
            GUICtrlSetData( $Button1, 'Loaded From Script Directory' )
            GUICtrlSetState( $Button1, $GUI_DISABLE )
        EndSwitch
        Sleep(10)
WEndoÝ÷ Û­Øb±·¢az)©¢»ZÚZ®Ö®¶­sbb33c¶fÆRÒfÆT÷VäFÆörb33´÷VâFRFW7BfÆRâââb33²ÂFV×F"ÂgV÷C·FW7BfÆRFW7BçGBgV÷C²ÂÂb33·FW7BçGBb33²Âb33c´f÷&Ó¢b33c·72Ò7G&æu7ÆBb33c¶fÆRÂgV÷C²b3#²gV÷C²¢b33c´fÆTæÖRÒb33c·75²b33c·75³ÕÒ²gVÆÂæWrÆö6FöâvFöÆBfÆVæÖRÒ67&DF"fײgV÷C²b3#²gV÷C²fײb33c´fÆTæÖP

EDIT: Variable name typo in comment

Edited by danwilli

Share this post


Link to post
Share on other sites
Wolfx128

Then I guess this would be a demonstration of what I think you are asking:

Yes Wootz... Sorry about this guys I just started picking up AutoIt like 3 days ago. Getting along nicely though and I love it much.

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.