Jump to content

BrowseFile Error


Kivin
 Share

Recommended Posts

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?

Link to comment
Share on other sites

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

Link to comment
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 *

Link to comment
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

Link to comment
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 *

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...