trof Posted April 21, 2017 Share Posted April 21, 2017 I use this script to paste clipboard to a text file #include <FileConstants.au3> Local Const $sFile = @WorkingDir & "\Testo.txt" Local $iFileExists = FileExists($sFile) Local $sData = ClipGet() Global $s_FilePath = @WorkingDir & "\Testo.txt" Global $s_EndChars = @CRLF Global $hFile = FileOpen($s_FilePath, 1) FileSetPos($hFile, -StringLen($s_EndChars), 1) If FileRead($hFile) <> $s_EndChars Then FileWrite($hFile, $s_EndChars) FileClose($hFile) If $iFileExists Then Global $s_FilePath = @WorkingDir & "\Testo.txt" Global $s_EndChars = @CRLF Global $hFile = FileOpen($s_FilePath, 1) FileSetPos($hFile, -StringLen($s_EndChars), 1) If FileRead($hFile) <> $s_EndChars Then FileWrite($hFile, $s_EndChars) FileClose($hFile) FileWriteLine(@WorkingDir & "\Testo.txt", @CRLF) FileWriteLine(@WorkingDir & "\Testo.txt", $sData) Else FileWriteLine(@WorkingDir & "\Testo.txt", $sData) EndIf However I prefer to choose filename, so I tried #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <StringConstants.au3> Local $sFileSaveDialog = FileSaveDialog("Save file", @WorkingDir, "(*.txt)") Local Const $sFile = @WorkingDir & $sFileSaveDialog Local $iFileExists = FileExists($sFile) Local $sData = ClipGet() Global $s_FilePath = @WorkingDir & $sFileSaveDialog Global $s_EndChars = @CRLF Global $hFile = FileOpen($s_FilePath, 1) FileSetPos($hFile, -StringLen($s_EndChars), 1) If FileRead($hFile) <> $s_EndChars Then FileWrite($hFile, $s_EndChars) FileClose($hFile) If $iFileExists Then Global $s_FilePath = @WorkingDir & $sFileSaveDialog Global $s_EndChars = @CRLF Global $hFile = FileOpen($s_FilePath, 1) FileSetPos($hFile, -StringLen($s_EndChars), 1) If FileRead($hFile) <> $s_EndChars Then FileWrite($hFile, $s_EndChars) FileClose($hFile) FileWriteLine(@WorkingDir & $sFileSaveDialog, @CRLF) FileWriteLine(@WorkingDir & $sFileSaveDialog, $sData) Else FileWriteLine(@WorkingDir & $sFileSaveDialog, $sData) EndIf Save dialog windows appears, but file is not saved Link to comment Share on other sites More sharing options...
KickStarter15 Posted April 21, 2017 Share Posted April 21, 2017 Hi, Not sure if this is what you mean. Try: #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <StringConstants.au3> Local $sFileSaveDialog = FileSaveDialog("Save file", @WorkingDir, "(*.txt)") Local Const $sFile = @WorkingDir & $sFileSaveDialog Local $iFileExists = FileExists($sFile) Local $sData = ClipGet() Global $s_FilePath = @WorkingDir & $sFileSaveDialog Global $s_EndChars = @CRLF Global $hFile = FileOpen($s_FilePath, 1) FileSetPos($hFile, -StringLen($s_EndChars), 1) If FileRead($hFile) <> $s_EndChars Then FileWrite($hFile, $s_EndChars) FileClose($hFile) If $iFileExists Then Global $s_FilePath = $sFileSaveDialog Global $s_EndChars = @CRLF Global $hFile = FileOpen($s_FilePath, 1) FileSetPos($hFile, -StringLen($s_EndChars), 1) If FileRead($hFile) <> $s_EndChars Then FileWrite($hFile, $s_EndChars) FileClose($hFile) FileWriteLine($sFileSaveDialog, @CRLF) FileWriteLine($sFileSaveDialog, $sData) Else FileWriteLine($sFileSaveDialog, $sData) MsgBox("","",$sData) Exit EndIf trof 1 Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare. Link to comment Share on other sites More sharing options...
trof Posted April 21, 2017 Author Share Posted April 21, 2017 Thanks, File is saved, but Save dialog initial path is not @WorkingDir and also it appears a popup with the content of the clipboard and it's annoying Link to comment Share on other sites More sharing options...
trof Posted April 21, 2017 Author Share Posted April 21, 2017 (edited) With this script I don't have the popup Local Const $sMessage = "Choose a filename." Local $sFileSaveDialog = FileSaveDialog($sMessage, @WorkingDir, "(*.txt)") Local Const $sFile = @WorkingDir & $sFileSaveDialog Local $iFileExists = FileExists($sFile) Local $sData = ClipGet() Global $s_FilePath = @WorkingDir & $sFileSaveDialog Global $s_EndChars = @CRLF Global $hFile = FileOpen($s_FilePath, 1) FileSetPos($hFile, -StringLen($s_EndChars), 1) If FileRead($hFile) <> $s_EndChars Then FileWrite($hFile, $s_EndChars) FileClose($hFile) If $iFileExists Then Global $s_FilePath = $sFileSaveDialog Global $s_EndChars = @CRLF Global $hFile = FileOpen($s_FilePath, 1) FileSetPos($hFile, -StringLen($s_EndChars), 1) If FileRead($hFile) <> $s_EndChars Then FileWrite($hFile, $s_EndChars) FileClose($hFile) FileWriteLine($sFileSaveDialog, @CRLF) FileWriteLine($sFileSaveDialog, $sData) Else FileWriteLine($sFileSaveDialog, $sData) EndIf but again @WorkingDir doesn't work Edited April 21, 2017 by trof Link to comment Share on other sites More sharing options...
KickStarter15 Posted April 21, 2017 Share Posted April 21, 2017 Hi trof, Actually you there is no need to use @WorkingDir if you have FileSaveDialog() when doing FileWriteLine(). It's enough to have it this way: Local $sFileSaveDialog = FileSaveDialog("Save file", @WorkingDir, "(*.txt)") 6 minutes ago, trof said: but Save dialog initial path is not @WorkingDir Please check again, I think SaveDialog() already has @WorkingDir as initial path. 8 minutes ago, trof said: also it appears a popup with the content of the clipboard and it's annoying Just remove the "MsgBox()" I just added it to validate ClipGet() function. Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare. Link to comment Share on other sites More sharing options...
trof Posted April 21, 2017 Author Share Posted April 21, 2017 I confirm that initial path it's not @WorkingDir Link to comment Share on other sites More sharing options...
KickStarter15 Posted April 21, 2017 Share Posted April 21, 2017 (edited) In my attached screenshot for FilesaveDialog() I already have the initial path in saving the file. Is this what you mean? Edited April 21, 2017 by KickStarter15 Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare. Link to comment Share on other sites More sharing options...
trof Posted April 21, 2017 Author Share Posted April 21, 2017 Yes, I'd like to have this Link to comment Share on other sites More sharing options...
KickStarter15 Posted April 21, 2017 Share Posted April 21, 2017 In help file, "init dir" is the initial directory for FileSaveDialog("title","init dir","filter"). Check having it like below "@WorkindDir" was already declared: Local $sFileSaveDialog = FileSaveDialog($sMessage, @WorkingDir, "(*.txt)") And have it like this: Local Const $sMessage = "Choose a filename." Local $sFileSaveDialog = FileSaveDialog($sMessage, @WorkingDir, "(*.txt)") Local Const $sFile = $sFileSaveDialog Local $iFileExists = FileExists($sFile) Local $sData = ClipGet() Global $s_FilePath = $sFileSaveDialog Global $s_EndChars = @CRLF Global $hFile = FileOpen($s_FilePath, 1) FileSetPos($hFile, -StringLen($s_EndChars), 1) If FileRead($hFile) <> $s_EndChars Then FileWrite($hFile, $s_EndChars) FileClose($hFile) If $iFileExists Then Global $s_FilePath = $sFileSaveDialog Global $s_EndChars = @CRLF Global $hFile = FileOpen($s_FilePath, 1) FileSetPos($hFile, -StringLen($s_EndChars), 1) If FileRead($hFile) <> $s_EndChars Then FileWrite($hFile, $s_EndChars) FileClose($hFile) FileWriteLine($sFileSaveDialog, @CRLF) FileWriteLine($sFileSaveDialog, $sData) Else FileWriteLine($sFileSaveDialog, $sData) EndIf Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare. Link to comment Share on other sites More sharing options...
trof Posted April 21, 2017 Author Share Posted April 21, 2017 Autoit remember the last path used in previous FilesaveDialog Link to comment Share on other sites More sharing options...
KickStarter15 Posted April 21, 2017 Share Posted April 21, 2017 (edited) So you need the next saving path will be initially the previous path? Or you mean when choosing a new path, still the last path was retain in FilesaveDialog()? Edited April 21, 2017 by KickStarter15 Edited Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare. Link to comment Share on other sites More sharing options...
trof Posted April 21, 2017 Author Share Posted April 21, 2017 No, I use the script from Windows context menu. I edit my registry and everything works well. Thanks Link to comment Share on other sites More sharing options...
KickStarter15 Posted April 21, 2017 Share Posted April 21, 2017 Well, good to hear. Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare. Link to comment Share on other sites More sharing options...
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