0

I created a simple application to allow users to register, add friends, and send private DM's.

I made the mistake of using local paths relative to my machine to import/export fstream .txt files for storage.

For example, the global list of users is located in:

C:\Users\19097\Desktop\Programs\Registration Application\App files\usernames\usernames.txt

This will obviously not work when ran on another computer. So my question, how can I create this directory of Storage for the objects in the app relative to the user?

I have briefly read on environment variables and from my understanding of it, they are used to reference various default window paths.

Since I do not know where the user would install and save the application files, how can I still create and read files dynamically, within a certain path relative to the computer it is installed on?

For example:

[Whatever this path is]\Registration Application\App files\usernames\usernames.txt

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
Leo
  • 51
  • 6
  • 1
    The directory part is available from an environment variable. – πάντα ῥεῖ Jan 22 '22 at 07:50
  • 3
    Rather than environment variables you are expected to use the known folders api – David Heffernan Jan 22 '22 at 08:26
  • *"relative to the user"* - Do you need a path relative to the user's environment, or do you need a path that's relative to the location of the running executable? – IInspectable Jan 22 '22 at 08:52
  • Whatever would be a better implementation honestly. Relative to the executable seems easier to use, however, would it be able to find the paths, if downloaded to different locations? – Leo Jan 22 '22 at 20:19
  • Relative to the app's folder is doable, but not a good idea. One, because users might install it under a protected folder, like Program Files. And two, it prevents multiple users on the same PC from sharing the app without also sharing their data. Better is to save the data in a folder under each user's profile. Make `[Whatever this path is]` be the result of either `SHGetFolderPath(CSIDL_(LOCAL_)APPDATA)` or `SHGetKnownFolderPath(FOLDERID_(Roaming|Local)AppData)` – Remy Lebeau Jan 23 '22 at 00:09

0 Answers0