quannguyen95 Posted February 9, 2017 Posted February 9, 2017 (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! Edited February 9, 2017 by quannguyen95
Subz Posted February 9, 2017 Posted February 9, 2017 You mean with something like: FileSaveDialog('Save File',@DesktopDir, 'Images (*.png)')
antonioj84 Posted September 15, 2017 Posted September 15, 2017 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
KaFu Posted September 15, 2017 Posted September 15, 2017 Prepending the folder to the filename works fine for me. ControlSetText("Save As", "", "Edit1", @DesktopDir & "\test.png") ControlClick("Save As", "", "Button2") OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
antonioj84 Posted September 15, 2017 Posted September 15, 2017 NO can do for me, would be kind to post your full code. here is my code where did I go wrong FileSaveDialog("save as",@ProgramFilesDir &"\Epson\JavaPOS\SetupPOS",'XML(*.xml)',0,"Jpos.xml") WinActivate("Save as ") $wnd=WinGetHandle('Save as','') ControlSend($wnd,"",'[CLASS:Button; INSTANCE:2;Text:Save]',"!s") ControlClick($wnd,'', 'button2')
Danp2 Posted September 15, 2017 Posted September 15, 2017 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. Latest Webdriver UDF Release Webdriver Wiki FAQs
antonioj84 Posted September 15, 2017 Posted September 15, 2017 (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 expandcollapse popup;*********************************************************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 September 15, 2017 by antonioj84 update
Danp2 Posted September 15, 2017 Posted September 15, 2017 FileSaveDialog doesn't save a file. Rather, it presents the end-user with a file save dialog where they can navigate and provide input. Latest Webdriver UDF Release Webdriver Wiki FAQs
antonioj84 Posted September 15, 2017 Posted September 15, 2017 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
Danp2 Posted September 15, 2017 Posted September 15, 2017 I see you are already using FileOpen and FileWrite. Is that not working for you? Latest Webdriver UDF Release Webdriver Wiki FAQs
antonioj84 Posted September 15, 2017 Posted September 15, 2017 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 ?
Danp2 Posted September 15, 2017 Posted September 15, 2017 ;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) Latest Webdriver UDF Release Webdriver Wiki FAQs
antonioj84 Posted September 15, 2017 Posted September 15, 2017 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
antonioj84 Posted September 17, 2017 Posted September 17, 2017 (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 September 17, 2017 by antonioj84 error
Danp2 Posted September 17, 2017 Posted September 17, 2017 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. Latest Webdriver UDF Release Webdriver Wiki FAQs
antonioj84 Posted September 17, 2017 Posted September 17, 2017 Thanks Danp2, Excellent point. Done !!
Danp2 Posted September 17, 2017 Posted September 17, 2017 So does it now work without the save dialog aspect? Latest Webdriver UDF Release Webdriver Wiki FAQs
antonioj84 Posted September 17, 2017 Posted September 17, 2017 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now