Jump to content

Save file


trof
 Share

Recommended Posts

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

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

 

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

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...