Jump to content
Sign in to follow this  
trof

Save file

Recommended Posts

trof

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

Share this post


Link to post
Share on other sites
KickStarter15

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

 

  • Like 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.

Share this post


Link to post
Share on other sites
trof

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 

Share this post


Link to post
Share on other sites
trof

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 by trof

Share this post


Link to post
Share on other sites
KickStarter15

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.:D


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.

Share this post


Link to post
Share on other sites
trof

I confirm that initial path it's not @WorkingDir

Share this post


Link to post
Share on other sites
KickStarter15

In my attached screenshot for FilesaveDialog() I already have the initial path in saving the file. Is this what you mean?

FileSaveDialog at WorkingDir.png

Edited 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.

Share this post


Link to post
Share on other sites
trof

Yes, I'd like to have this

Share this post


Link to post
Share on other sites
KickStarter15

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.

Share this post


Link to post
Share on other sites
trof

Autoit remember the last path used in previous  FilesaveDialog

Share this post


Link to post
Share on other sites
KickStarter15

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 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.

Share this post


Link to post
Share on other sites
trof

No,

I use the script from Windows context menu. I edit my registry and everything works well.

Thanks

 

Share this post


Link to post
Share on other sites
KickStarter15

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.

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  

×