Sign in to follow this  
Followers 0
twelo

file save problem

6 posts in this topic

i want to save file from my gui -> editbox

here my save function

Func _Save()
        $file_save = FileSaveDialog("Save...", @DesktopDir, "Text Files (*.txt) | All Files (*.*)", 18, "", $MyGUI)
        If @error then Return(0)
        If StringInStr($file_save, ".", 0, -1) Then $file_save = StringMid($file_save, 1, StringInStr($file_save, ".", 0, -1) - 1)
        If $file_save <> "" Then
        $read = GUICtrlRead($EditBox)
        FileWrite($file_save & ".txt", $read)
        EndIf
EndFunc

1. unicode issue: i can open, read, write unicode files & characters in editbox. but i can not save file with unicode characters. output comes like ????? ??? ?????

how to save unicode characters ?

2. overwrite issue: whenever it saves or overwrite existing files. it adds the new content at the end of old file content. like i open a file with content "123" written, i added "456" & save or overwrite then output comes like "123123456"

how to fix it ?

3. extension issue: my gui supports .txt & *.* extension. but when i save file with *.* without any extension. saved output file comes with txt extension.

and when i remove .txt from "FileWrite($file_save & ".txt", $read)" then it always save files without any extension.

how to fix it ?

help ;)

Share this post


Link to post
Share on other sites



twelo,

I think the problems 1 & 2 would be solved if you used FileOpen to open the file in the correct mode before writing to it - go and read the Help file page for FileOpen to see what is available. Remember that you will then need to use the file handle in your FileWrite command, and that you must use FileClose afterwards to free the handle. :evil:

As for problem 3, it looks as if you are getting exactly what you asked for:

saved output file comes with txt extension and when i remove .txt from "FileWrite($file_save & ".txt", $read)" then it always save files without any extension.

if you set the filename to be $file_save & ".txt", why would AutoIt save it without an extension? ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

if you set the filename to be $file_save & ".txt", why would AutoIt save it without an extension? ;)

M23

in filesavedialog i assign filter ".txt" & "*.*"

but without $file_save & ".txt" it always save without any extension & with $file_save & ".txt" it always save with .txt extension

how to save both, mean .txt & any extension (*.*)

Share this post


Link to post
Share on other sites

twelo,

When you use the "Save" dialog, the file is not given the extension you select in the "Save as type" combo. All that does is to show the files which match that filter if you use the "Browse folders" feature. You have to specify the extension you want if you are saving a new file rather than overwriting a previous one. So if you want a .txt extension, you have to add it to the filename yourself. I agree this is not what you would immediately think will happen - but that is what the dialog actually does! Go and try it yourself. :evil:

However, even if you added the .txt extension manually, you then run this line:

If StringInStr($file_save, ".", 0, -1) Then $file_save = StringMid($file_save, 1, StringInStr($file_save, ".", 0, -1) - 1)

which promptly removes the .txt extension from any filename which has it. So regardless of what you entered in the "Save" dialog, you now have NO extension. ;)

Finally you use this line:

FileWrite($file_save & ".txt", $read)

to add a .txt extension to the filename - and guess what, you get the filename with .txt extension regardless of what you selected in the "Save" dialog! :evil:

The solution is very simple - add the extension you want when you use the "Save" dialog (because it will not do it for you as explained above) and just use the filename that is returned.

$file_save = FileSaveDialog("Save...", @ScriptDir, "Text Files (*.txt) | All Files (*.*)", 18, "")
If @error Then Exit
FileWrite($file_save, "Test")

Note that you do not need the

If $file_save <> ""

check. Did you actually try to save a blank filename? You will find that the "Save" dialog will not let you! :idea:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

When you use the "Save" dialog, the file is not given the extension you select in the "Save as type" combo. All that does is to show the files which match that filter if you use the "Browse folders" feature.

now i understand, i was messing with all my codes to get extension with filter :evil:

it sorted out with save(.txt) & save as(*.*) dialog (problem 3 solved)

(problem 2 solved) used filewritetoline to save file from the 1st line.

but i can't figure out unicode problem ;)

fileopen, fileclose, & filewrite commands will be use for this, but how ?

what if we want to save directly from editbox without open any file ?

and when i use fileopen to open files with UTF 16(32) mode, regular text files not shows correctly.

and how to get filehandle & config it with filewrite command

any example wud br gr8

Share this post


Link to post
Share on other sites

twelo,

what if we want to save directly from editbox without open any file ?

I believe you MUST use FileOpen to open the file in the correct file format if you want to save UniCode. And I do not believe you can alter the format with FileWrite - that is why FileOpen has the flags it does. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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