0

I have multiple data files that are named after what they contain. For example

machine-testM_pid-1234_key1-value1.log

There are keys and values separated by - and _. Is there a better syntax for this? Are there parsers that automatically read these kinds of files/filenames?

The idea here is that the filenames are human and machine readable.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Juha
  • 2,053
  • 23
  • 44

3 Answers3

1

8 years later...

I would suggest that you look into https://en.wikipedia.org/wiki/Query_string

They aren't pretty filenames, but you wouldn't have to re-invent the wheel with for example converting to dict/json since there are well-tested methods for parsing query strings, for example in the requests library.

There's a related question over at https://unix.stackexchange.com/questions/44153/good-style-practices-for-separators-in-file-or-directory-names as well that contains some useful information that contains some ideas for better visual separators (_-_ and ___) that might be better in this case

OlleNordesjo
  • 133
  • 1
  • 7
0

There seems to be no standard file naming convention for key-values.

Juha
  • 2,053
  • 23
  • 44
0

the most basic type of KEY=VALUE files with pretty much strict syntax i know would be:

  • .properties mostly for java configuration-files, they allow comments
  • .env mostly for unix, systemd-service environment files, they allow comments
  • .ini mostly for c#,python,... applications, they allow comments and [sections] aswell

(you can mix and still use them though, that's just my experience how developers are naming their stuff based on libraries e.t.c.)

and there are a lot more with slightly different syntax, for example

  • .json files and/or syntax "key":"value"
  • .yaml files and/or syntax key: "value"
  • .xml files and/or syntax <key>value</key>
  • custom stuff based on the application can be key=value too, but doesn't have to ... look for something like .cfg , .conf , .config , .preferences, .settings, ...

hope that helps.

zeg
  • 432
  • 2
  • 9