Sign in to follow this  
Followers 0
Kivin

BrowseFile Error

8 posts in this topic

Hi everyone!

There is my script:

#include <GUIConstants.au3>

If Not  FileExists  ( "..\Settings.ini" ) Then
        FileWrite   ( "..\Settings.ini" , ""    )
        IniWrite    ( "..\Settings.ini" , "Path", "DestinationPath" , @DesktopDir )
        IniWrite    ( "..\Settings.ini" , "Path", "SourcePath"      , @DesktopDir )
EndIf

$DestinationPath    = IniRead ("..\Settings.ini" , "Path", "DestinationPath"    , "" )
$SourcePath         = IniRead ("..\Settings.ini" , "Path", "SourcePath"     , "" )

$MainWindow                 = GUICreate             ("Title window"         , 600,160)
GUISetState (@SW_SHOW)
$SourceLabel                = GUICtrlCreateLabel    ( "Source:"             ,  10, 10)
$SourceInput                = GUICtrlCreateInput    ( $SourcePath           , 100,  8,400, 20)
$SourceBrowseButton         = GUICtrlCreateButton   ( "Browse"              , 510,  6, 70, 25)
$DestinationLabel           = GUICtrlCreateLabel    ( "Destination:"        ,  10, 50)
$DestinationInput           = GUICtrlCreateInput    ( $DestinationPath      , 100, 48,400, 20)
$DestinationBrowseButton    = GUICtrlCreateButton   ( "Browse"              , 510, 46, 70, 25)
$ExitButton                 = GUICtrlCreateButton   ( "Exit"                , 510,126, 70, 25)

Func BrowseFile ()
    $TempVariable = FileOpenDialog  ( "Choose playlist", $SourcePath    , "All files (*.*)",1)
    If Not @error Then
        GUICtrlSetData  ( $SourceInput, $TempVariable )
;~      MsgBox (0,"",$TempVariable); I try this line to find my error
        IniWrite        ( "..\Settings.ini" , "Path", "SourcePath"      , $TempVariable); here is my problem line
    EndIf
EndFunc


Func BrowseFolder ()
    $TempVariable = FileSelectFolder( "Choose Destination", "",2 )
    If Not @error Then
        GUICtrlSetData  ( $DestinationInput, $TempVariable )
        IniWrite        ( "..\Settings.ini" , "Path", "DestinationPath" , $TempVariable)
    EndIf
EndFunc

Do
    $msg = GUIGetMsg ( 1 )
    Select
        Case $msg[0] = $SourceBrowseButton
            BrowseFile ()
        Case $msg[0] = $DestinationBrowseButton
            BrowseFolder ()
    EndSelect
Until $msg[0] = $GUI_EVENT_CLOSE Or $msg[0] = $ExitButton

Main function is remember last chosen path to Source file & to Destination folder after pushing browse button & show it after restarting program.

Func BrowseFolder work perfect!

But Func BrowseFile

There is some problem!

P.S. If change Settings.ini file path (replace all "..\Settings.ini" with @ScriptDir & "\Settings.ini") everything work perfect!

Where is my error?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Here, this worked for me:

#include <GUIConstants.au3>

If Not  FileExists   ( @ScriptDir & "\..\Settings.ini" ) Then
        ;FileWrite   ( "..\Settings.ini" , ""  ) You don't need this
        IniWrite    (@ScriptDir & "\..\Settings.ini", "Path", "DestinationPath", @DesktopDir )
        IniWrite    (@ScriptDir & "\..\Settings.ini" , "Path", "SourcePath", @DesktopDir )
EndIf

$DestinationPath    = IniRead ("..\Settings.ini" , "Path", "DestinationPath"    , "" )
$SourcePath         = IniRead ("..\Settings.ini" , "Path", "SourcePath"  , "" )

$MainWindow                 = GUICreate    ("Title window"      , 600,160)
GUISetState (@SW_SHOW)
$SourceLabel                = GUICtrlCreateLabel    ( "Source:"                ,  10, 10)
$SourceInput                = GUICtrlCreateInput    ( $SourcePath      , 100,  8,400, 20)
$SourceBrowseButton         = GUICtrlCreateButton   ( "Browse"                , 510,  6, 70, 25)
$DestinationLabel         = GUICtrlCreateLabel   ( "Destination:"      ,  10, 50)
$DestinationInput         = GUICtrlCreateInput   ( $DestinationPath        , 100, 48,400, 20)
$DestinationBrowseButton    = GUICtrlCreateButton  ( "Browse"            , 510, 46, 70, 25)
$ExitButton                 = GUICtrlCreateButton   ( "Exit"        , 510,126, 70, 25)

Func BrowseFile ()
    $TempVariable = FileOpenDialog  ( "Choose playlist", $SourcePath , "All files (*.*)",1)
    If Not @error Then
        GUICtrlSetData  ( $SourceInput, $TempVariable )
        ;MsgBox (0,"",$TempVariable); I try this line to find my error
        ConsoleWrite(IniWrite  ( @ScriptDir & "\..\Settings.ini" , "Path", "SourcePath", $TempVariable)); here is my problem line
    EndIf
EndFunc


Func BrowseFolder ()
    $TempVariable = FileSelectFolder( "Choose Destination", "",2 )
    If Not @error Then
        GUICtrlSetData  ( $DestinationInput, $TempVariable )
        IniWrite( @ScriptDir & "\..\Settings.ini" , "Path", "DestinationPath", $TempVariable)
    EndIf
EndFunc

Do
    $msg = GUIGetMsg ( 1 )
    Select
        Case $msg[0] = $SourceBrowseButton
            BrowseFile ()
        Case $msg[0] = $DestinationBrowseButton
            BrowseFolder ()
    EndSelect
Until $msg[0] = $GUI_EVENT_CLOSE Or $msg[0] = $ExitButton

EDIT

Fixed the ones at the top too

Edited by The Kandie Man

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Share this post


Link to post
Share on other sites

Just a thought, but have you tried using another directory instead of @DesktopDir?


----[ SandyD ]---

Share this post


Link to post
Share on other sites

Hi everyone!

There is my script:

P.S. If change Settings.ini file path (replace all "..\Settings.ini" with @ScriptDir & "\Settings.ini") everything work perfect!

Where is my error?

FileOpenDialog() changes the working dir (see help file), so your path "..\Settings.ini" might not make sense after calling that function. NEVER

use relative paths (..\xyz), ALWAYS use absolut paths (@ScriptDir\Settings.ini).


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

FileOpenDialog() changes the working dir (see help file), so your path "..\Settings.ini" might not make sense after calling that function. NEVER

use relative paths (..\xyz), ALWAYS use absolut paths (@ScriptDir\Settings.ini).

(@ScriptDir\Settings.ini) = or <> (@ScriptDir & "\Settings.ini") ????

Thanks


One is never too old to learn

Share this post


Link to post
Share on other sites

(@ScriptDir\Settings.ini) = or <> (@ScriptDir & "\Settings.ini") ????

Thanks

well, the correct AU3 syntax is obviously: @ScriptDir & "\Settings.ini". I was just giving an example....


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

well, the correct AU3 syntax is obviously: @ScriptDir & "\Settings.ini". I was just giving an example....

I see ,Thanks any way


One is never too old to learn

Share this post


Link to post
Share on other sites

Thanks all of you for help. I understand my error.

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