Jump to content

How to set docs save location depending on user preferences


Recommended Posts

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 post
Share on other sites

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 post
Share on other sites
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 by Davidowicza
Link to post
Share on other sites

@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 :)

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to post
Share on other sites

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 post
Share on other sites

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 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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...