stick3r Posted September 21, 2018 Share Posted September 21, 2018 Hi, The title might not be correct, I don't know how to set the issue in the title shortly. I set default documents save location as @DesktopDir. The is gonna be many users of that script and all of them might need to save it in different locations. So they can choose Default location for themself. What I need is to let user not only to choose document save location, but I want script to remember their location even after closing script and opening it next day. How to do that? I would try to google it, but I don't know what I am looking for Link to comment Share on other sites More sharing options...
Developers Jos Posted September 21, 2018 Developers Share Posted September 21, 2018 Use an INI file with the appropriate functions in the script? Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Davidowicza Posted September 21, 2018 Share Posted September 21, 2018 Try looking at FileSaveDialog to get where the user wants to save it and you can write where they want to save it into a .txt file on their computer. Just have the script check if there is anything written in that file before you prompt where they want to save it. Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted September 21, 2018 Share Posted September 21, 2018 @stick3r As @Jos and @Davidowicza suggested, an INI file and the FileSaveDialog are what you're looking for Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
stick3r Posted September 21, 2018 Author Share Posted September 21, 2018 FileSaveDialog is all clear for me. However, I have never worked with INI files. So in theory I let user to choose directory with FileSaveDialog, then create INI file and save it somewhere in users pc with the location path in that file and everytime they save the document, script goes to INI file to check the user's selected location? Where are INI files generally kept? Link to comment Share on other sites More sharing options...
Davidowicza Posted September 21, 2018 Share Posted September 21, 2018 (edited) 5 minutes ago, stick3r said: FileSaveDialog is all clear for me. However, I have never worked with INI files. So in theory I let user to choose directory with FileSaveDialog, then create INI file and save it somewhere in users pc with the location path in that file and everytime they save the document, script goes to INI file to check the user's selected location? Where are INI files generally kept? INI files can be kept anywhere. Look at this website under how they are structured so you know how to set up your key. Edited September 21, 2018 by Davidowicza Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted September 21, 2018 Share Posted September 21, 2018 @stick3r INI files are useful when you have to store some informations. Take a look at this: #include <MsgBoxConstants.au3> Global $strINIFile = @ScriptDir & "\INIFile.ini", _ ; INI in which you store the "save path" $strFileSavePath = "", _ ; Save path obtained from FileSaveDialog() $arrINISectionValues ; If a SavePath is set, show the SetPath set. $strFileSavePath = FileSaveDialog("Save file", @ScriptDir, "Text files (*.txt)") If @error = 1 Then MsgBox($MB_ICONERROR, "", "File selection failed." & @CRLF & _ "Error: " & @error) Exit ElseIf @error = 2 Then MsgBox($MB_ICONERROR, "", "Bad file filter." & @CRLF & _ "Error: " & @error) Exit Else IniWrite($strINIFile, "Options", "SavePath", $strFileSavePath) EndIf $arrINISectionValues = IniReadSection($strINIFile, "Options") If @error Then MsgBox($MB_ICONERROR, "", "Error while reading the section of the file '" & @CRLF & _ $strINIFile & "'." & @CRLF & _ "Error: " & @error) Else MsgBox($MB_ICONINFORMATION, "", "The file will be saved in '" & $arrINISectionValues[1][1] & "' folder.") EndIf Cheers kebab 1 Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
Subz Posted September 22, 2018 Share Posted September 22, 2018 Or use registry Local $sUserRegPath = "HKCU\Software\MyScript" ;~ Checks to see if HKEY_CURRENT_USER\Software\MyScript, SavePath key is a valid directory, if no then set the default save path to @DesktopDir Local $sFileSavePath = FileExists(RegRead($sUserRegPath, "SavePath")) = 0 ? @DesktopDir : RegRead($sUserRegPath, "SavePath") ;~ Writing the path ;~ RegWrite($sUserRegPath, "SavePath", "REG_SZ", "<Folder Save Path>") Link to comment Share on other sites More sharing options...
stick3r Posted September 22, 2018 Author Share Posted September 22, 2018 I am not sure if I will be able to use registry at work computer Anyway, I think I am good now with the code, I watched this video, which helped me to see and understand basics of what is happening in INI files and then modified @FrancescoDiMuro code to fit my needs. I will try it at work on Monday. Thank you for your help, I have learned new things Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted September 22, 2018 Share Posted September 22, 2018 @stick3r Happy to have helped Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette 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