Jump to content
Sign in to follow this  
Juzzz

Save an file

Recommended Posts

Juzzz

I want to save something with AutoIT but i can't figure out how..

ok, i want to save an existing file to somewhere else with a different name.

the original file is an .ini file and changes when i press some buttons.

i found:

_WinAPI_GetSaveFileName("Save as", "MS ini file(*.ini)|All files (*.*)", @ScriptDir, "My Setup", ".ini")

fileWrite()

consoleWrite()

but i really can't figure out how..

ps. if some one know how to load the new file thanks.

Share this post


Link to post
Share on other sites
DaRam

Are you sure you are not just looking to Copy a File?

Share this post


Link to post
Share on other sites
Szhlopp

I want to save something with AutoIT but i can't figure out how..

ok, i want to save an existing file to somewhere else with a different name.

the original file is an .ini file and changes when i press some buttons.

i found:

_WinAPI_GetSaveFileName("Save as", "MS ini file(*.ini)|All files (*.*)", @ScriptDir, "My Setup", ".ini")

fileWrite()

consoleWrite()

but i really can't figure out how..

ps. if some one know how to load the new file thanks.

Use the iniread/write commands and the Fileread/write/open. Check the Help file.

Share this post


Link to post
Share on other sites
Juzzz

i came to this code for save:

Case $msg = $menuitem_Save
            $save = FileSaveDialog( "Save as", @ScriptDir, "MS ini file(*.ini)", 2)
            FileCopy(@ScriptDir & "\Lights.ini", $save & ".ini")

but its not an correct save as menu. + it does not over write if you want (it just add "filename.ini.ini")

can some one just give me an example of an working save as option (+ read, like an prompt to load/select an file)

Share this post


Link to post
Share on other sites
DaRam

Here you go:

;#NoTrayIcon
#include <WindowsConstants.au3>
#include <GUIConstants.au3>

$frmMain = GUICreate("Test", 640, 150, -1, -1)
GUISetStyle(BitOR($WS_MINIMIZEBOX, $WS_MAXIMIZEBOX, $WS_SIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU))

; Menu System
$MenuFile = GUICtrlCreateMenu("&File")
$mnuFileSource = GUICtrlCreateMenuItem("Select &Source", $MenuFile)
$mnuFileTarget = GUICtrlCreateMenuItem("Select &Target", $MenuFile)
GUICtrlCreateMenuItem("", $MenuFile)
$mnuFileCopy    = GUICtrlCreateMenuItem("&Copy", $MenuFile)
GUICtrlCreateMenuItem("", $MenuFile)
$mnuFileExit    = GUICtrlCreateMenuItem("E&xit", $MenuFile)

$Btn_Source = GUICtrlCreateButton("Source:", 8, 8, 73, 25, 0)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKSIZE)
GUICtrlSetTip(-1, " Select Source File ")

$Btn_Target = GUICtrlCreateButton("Target:", 8, 40, 73, 25, 0)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKSIZE)
GUICtrlSetTip(-1, " Select Target File ")

$Txt_Source = GUICtrlCreateInput("", 88, 8, 540, 21)
GUICtrlSetResizing(-1, $GUI_DOCKTOP + $GUI_DOCKLEFT + $GUI_DOCKHEIGHT)
$Txt_Target = GUICtrlCreateInput("", 88, 40, 540, 21)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKHEIGHT)

$Btn_Copy = GUICtrlCreateButton("&Copy", 532, 72, 97, 25, 0)
GUICtrlSetResizing(-1, $GUI_DOCKBOTTOM + $GUI_DOCKRIGHT + $GUI_DOCKSIZE)
GUICtrlSetTip(-1, " Start Copy Operation ")

GUISetState(@SW_SHOW)

While 1
  Switch GUIGetMsg()
  Case $GUI_EVENT_CLOSE, $mnuFileExit
       ExitLoop
  Case $Btn_Source, $mnuFileSource
       $Fn = FileOpenDialog(GUICtrlRead($Btn_Source), default, "Ini Files (*.ini)", 1 + 4, GUICtrlRead($Txt_Source), $frmMain )
       if StringLen($Fn) > 0 Then
            GUICtrlSetData($Txt_Source, $Fn)
            if StringLen(GUICtrlRead($Txt_Target)) < 1 Then GUICtrlSetData($Txt_Target, $Fn)
         EndIf
  Case $Btn_Target, $mnuFileTarget
       $Fn = FileSaveDialog(GUICtrlRead($Btn_Target), default, "Ini Files (*.ini)", 16, GUICtrlRead($Txt_Target), $frmMain )
       if StringLen($Fn) > 0 Then GUICtrlSetData($Txt_Target, $Fn)
  Case $Btn_Copy, $mnuFileCopy
       $Sf = GUICtrlRead($Txt_Source)
       $Tf = GUICtrlRead($Txt_Target)
       If StringLen($Sf) > 0 AND StringLen($Tf) > 0 Then
          If FileExists($Tf) Then
             If MsgBox(1 + 48, "Confirm Overwrite", "Overwrite" & @CRLF & $Tf & " ?") <> 1 Then ContinueLoop
          EndIf
          FileCopy($Sf, $Tf, 9); Flag = 1 + 8 (overwrite + create target directory structure)
          Sleep(100)
          If FileExists($Tf) Then
             MsgBox(64, "Copy Operation Completed", "Copy: " & $Sf & @CRLF & "To: " & $Tf)
          Else
             MsgBox(16, "Copy Operation Failed", "Copy: " & $Sf & @CRLF & "To: " & $Tf)
          EndIf
       EndIf
  EndSwitch
WEnd

Share this post


Link to post
Share on other sites
Juzzz

VERRY THANKS!

i can learn from that script very well thanks.

1 question

i see at the GUICtrlCreateMenu() funtion:

&File, and &Copy, and E&xit

whats the use of the "&" ?

Share this post


Link to post
Share on other sites
Tvern

1 question

i see at the GUICtrlCreateMenu() funtion:

&File, and &Copy, and E&xit

whats the use of the "&" ?

If you hold "Alt" you will see the letter after the "&" underlined. The underlined letter will act as a hotkey for that item.

In this example Alt+F will open the menu "File". Pressing Alt+X closes the program.

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.