Sign in to follow this  
Followers 0
trof

Save file

13 posts in this topic

#1 ·  Posted

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



#2 ·  Posted

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

 

1 person likes this

Share this post


Link to post
Share on other sites

#3 ·  Posted

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

#4 ·  Posted (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 by trof

Share this post


Link to post
Share on other sites

#5 ·  Posted

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

Share this post


Link to post
Share on other sites

#6 ·  Posted

I confirm that initial path it's not @WorkingDir

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#8 ·  Posted

Yes, I'd like to have this

Share this post


Link to post
Share on other sites

#9 ·  Posted

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

 

Share this post


Link to post
Share on other sites

#10 ·  Posted

Autoit remember the last path used in previous  FilesaveDialog

Share this post


Link to post
Share on other sites

#11 ·  Posted (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 by KickStarter15
Edited

Share this post


Link to post
Share on other sites

#12 ·  Posted

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

#13 ·  Posted

Well, good to hear.^_^

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  
Followers 0