quannguyen95

How to auto save a file in File Save Dialog Window in the desired folder

21 posts in this topic

#1 ·  Posted (edited)

Hi everyone,

I want to autosave a file, for example in a folder in desktop, how can I automatically change the directory to C:\Desktop\ in this File Save Dialog ?

Thank you so much!

How to autosave a file in the correct folder.png

Edited by quannguyen95

Share this post


Link to post
Share on other sites



FileSaveDialog("save as",@ProgramFilesDir &"\Epson\JavaPOS\SetupPOS",'XML(*.xml)',0,"Jpos.xml")
WinActivate("Save ")
$wnd=WinGetHandle('Save','')

ControlSend($wnd,'','','!')

;ControlSend($wnd,"",'[CLASS:Button; INSTANCE:2;Text:Save]',"s")
;ControlClick($wnd,'', 'button2')


$hWND = WinWait("[CLASS:DirectUIHWND; INSTANCE:2]")
WinActivate($hWnd)
Controlsend("[CLASS:DirectUIHWND; INSTANCE:2]", "", "[CLASS:Button; INSTANCE:2]","!s")
Send("{enter}")

 I am not able to click on the save button on windows 10, however windows7  work fine any help is appreciated

saveasCapture.JPG

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

Thanks I am going to try that

Share this post


Link to post
Share on other sites

Your script will pause after the first line of your script because it's waiting for user input in the Save File dialog.

Please explain why you are using this command (FileSaveDialog) when you are already determining the name and directory where the file is getting saved.

Share this post


Link to post
Share on other sites

Thanks I want it to auto save

 

Thanks

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Reason is,  this is part of a  bigger script, I am working  with an XML file,  however after making changes within the xml file, the changes appear to update only  if I save it as in that same directory. unless there is another way to save xml file

;*********************************************************Routine to add Ip address to pc.properties and  jpos.xml (printers and cash drawer); Sept 6 2017
Global $Jpos=@ProgramFilesDir&"\Epson\JavaPOS\SetupPOS\"&"Jpos.xml"
FileSetAttrib($Jpos & '\JPOS.xml', "-R")
 $ipvalue= "10.229.117.188" ;$tabprinter
 $xml = $Jpos




$pdata = FileRead($xml)



Local $posa1 = StringInStr($pdata, '"CashDrawer">')
_Replace($posa1, $ipvalue,$xml)
$pdata = FileRead($xml)

Local $posa2 = StringInStr($pdata, '"POSPrinter">')
_Replace($posa2, $ipvalue,$xml)


FileSetAttrib($Jpos & '\JPOS.xml', "+R")
FileClose($xml)
;~Local $hFileOpen = FileOpen($pdata, $FO_APPEND)
;~FileWriteLine($hFileOpen, "" & @CRLF & @CRLF)
;~FileClose($hFileOpen)






;************************************************************function to replace ip inside xlm s Epson********************


Func _Replace($PosData,$ipvalue,$xml)
$pos1 = $PosData


if $pos1>0 Then
    $pos2 = StringInStr($pdata, '</JposEntry', 0, 1, $pos1)
    if $pos2 > 0 Then
        $mdata = StringMid($pdata, $pos1, $pos2-$pos1)

        $p1 = StringInStr($pdata, 'name="PortName"', 0, 1, $pos1)
        if $p1<=$pos2 Then
            $p2 = StringInStr($pdata, '>', 0, 1, $p1)
            if $p2>0 Then
                $txt = StringMid($pdata, $p1, $p2-$p1)
                ;MsgBox(0, '1', $txt)
                $tmp = _StringBetween($txt, 'value="', '"')
                if not @error Then
                    $txt2 = StringReplace($txt, $tmp[0], $ipvalue)
                EndIf
                ;MsgBox(0, '2', $txt2)

                $mdata2 = StringReplace($mdata, $txt, $txt2)
                $pdata = StringReplace($pdata, $mdata, $mdata2)
                ConsoleWrite($pdata & @CRLF)

                $file = FileOpen($xml, 2)
                FileWrite($file, $pdata)
                ;FileSetAttrib(@ScriptDir & '\JPOS.xml', "+R")
                ;FileClose($file)
            EndIf
        EndIf
    EndIf
EndIf

EndFunc

 

Edited by antonioj84
update

Share this post


Link to post
Share on other sites

FileSaveDialog doesn't save a file. Rather, it presents the end-user with a file save dialog where they can navigate and provide input.

Share this post


Link to post
Share on other sites
35 minutes ago, Danp2 said:

FileSaveDialog doesn't save a file. Rather, it presents the end-user with a file save dialog where they can navigate and provide input.

Thanks, what do you suggest ? in that case. I have a work around but  it's ugly

Share this post


Link to post
Share on other sites

I see you are already using FileOpen and FileWrite. Is that not working for you?

Share this post


Link to post
Share on other sites
1 minute ago, Danp2 said:

I see you are already using FileOpen and FileWrite. Is that not working for you?

No it does not, the file will show kB = 0 even  though the data is updated,  once i do the "saves as" the  file size will show kb =11.  Is there something more I need to add in the code make sure its updated ?

Share this post


Link to post
Share on other sites
;FileClose($file)

You need to uncomment this line so that the file gets properly closed.

FYI, you can't call FileClose with a literal string like this.

FileClose($xml)

 

Share this post


Link to post
Share on other sites
44 minutes ago, Danp2 said:
;FileClose($file)

You need to uncomment this line so that the file gets properly closed.

FYI, you can't call FileClose with a literal string like this.

FileClose($xml)

 

You are correct, I have done the change, I will test Monday. Thanks for helping out

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

here is my solution. I created  dialogsaveas.exe  I anyone can improve on my code, you are welcome, let me know.

;;;;;; DialogSaveas.exe
Global $Jpos=@ProgramFilesDir&"\Epson\JavaPOS\SetupPOS\"&"Jpos.xml" ;path
FileSetAttrib($Jpos & '\JPOS.xml', "-R")  ; make file editable
FileSaveDialog("save as",@ProgramFilesDir &"\Epson\JavaPOS\SetupPOS",'XML(*.xml)',0,"Jpos.xml") ; create a save as dialog box
exit
;;;;; DialogSaveas.exe



Run('dialogSaveas.exe',@ScriptDir,@SW_HIDE) ; hide save dialog box
Sleep(250)   ;* sleep time require

WinActive("save as ")  
$Wnd=WinGetHandle('save as','')

while winExist($Wnd)
 ControlSend($Wnd,"",'[CLASS:Button; INSTANCE:2]',"!s")
Wend


;~if WinExists($Wnd) Then ControlSend($Wnd,"",'[CLASS:Button; INSTANCE:2]',"!s")
FileSetAttrib($Jpos & '\JPOS.xml', "+R") ; set read only

 

Edited by antonioj84
error

Share this post


Link to post
Share on other sites

If this works for you, great! I just don't see why it needs to be so convoluted. I would rewrite your original code something like this --

Local $Jpos=@ProgramFilesDir&"\Epson\JavaPOS\SetupPOS\"&"Jpos.xml"
Local $ipvalue= "10.229.117.188" ;$tabprinter

Local $pdata = FileRead($Jpos)
Local $posa1 = StringInStr($pdata, '"CashDrawer">')
_Replace($pdata, $posa1, $ipvalue)
Local $posa2 = StringInStr($pdata, '"POSPrinter">')
_Replace($pdata, $posa2, $ipvalue)

FileSetAttrib($Jpos, "-R")
Local $hFileOpen = FileOpen($pdata, $FO_OVERWRITE)
FileWrite($hFileOpen, $pdata)
FileClose($hFileOpen)
FileSetAttrib($Jpos, "+R")

so that all of the file reading, writing, etc occurs in the main code. Then the _Replace function only needs to change the IP address for the string that is already loaded into memory. This also reduces the file operations down to a single read/write combination.

Share this post


Link to post
Share on other sites

Thanks Danp2, Excellent point. Done !!

Share this post


Link to post
Share on other sites

So does it now work without the save dialog aspect?

Share this post


Link to post
Share on other sites
39 minutes ago, Danp2 said:

So does it now work without the save dialog aspect?

I have not check yet, I need to be on the lab, however I suspect after the correction you made on the codes, the savedialog may not be needed any longer. The save dialog was due to sloppy coding.

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