-2

This question already has an answer here:

My program (a command-line utility) will load configuration from a file, using defaults if file not found, and I'd like to do this in a cross-platform manner that people will expect.

Is there a de-facto standard or other common algorithm for searching directories to find the config file?

I'm imagining something like:

  • If Windows:
    • Try %appdata%\myprogram\config.cfg
    • Try same directory as binary
  • Otherwise:
    • Try $(HOME)/.myprogram/config.cfg
    • Try /etc/myprogram/config.cfg
    • Try same directory as binary

marked as duplicate by gnat, Jarrod Roberson, 8bittree, Robert Harvey, Community Jan 18 '18 at 21:01

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

-2

It depends. Do you provide an installer with the utility? Then you should put the file in the user data location for the platform. But you should also provide a configuration editor which could be as simple as another argument that kicks up a text editor with the cfg file. Then the user does not have to know where it is or search for the cfg file.

Config.cfg is a silly name that does not associate it to your utility in any way, it should be .xxx with xxx expressing the configurating nature of the file. If xxx is clearly data, like with xml, that could suffice but you may go a little more elaborate with something like

I would stick to a single location per platform, not have a number of fallback options, that would be an incomprehencible nightmare.

Having it in the same directory as the executable is only nice if you know the user will have write access to it.

Not the answer you're looking for? Browse other questions tagged or ask your own question.