0

I've converted the file libraryfolders.vdf into json using https://github.com/p0358/vdf-parser

Now i'm stuck with something like this:

"libraryfolders": {
    "0": {
        "path": "D:\\\\Program Files (x86)\\\\Steam",
        "label": "",
        "contentid": -3675068714072690700,
        "totalsize": 0,
        "update_clean_bytes_tally": 156136761200,
        "time_last_update_corruption": 0,
        "apps": {
            "357720": 1119505844,
            "367450": 222650546,
            "391540": 163095879,
        }
    },
    "1": {
        "path": "C:\\\\SteamLibrary",
        "label": "",
        "contentid": 8761260447083160000,
        "totalsize": 126696288256,
        "update_clean_bytes_tally": 0,
        "time_last_update_corruption": 0,
        "apps": {
            "433340": 1230903210,
        }
    }
}

I need to loop through all the libraries and get path for gameID. This is my code so far.

for (let i = 0; i < 999; i++) {
    let lib = json.libraryfolders[i];
    if (!lib) break;
    let path = lib.path;
    if (lib.apps.hasOwnProperty('433340')) {
        console.log("app found in " + path)
    }
}

And my question is: how can I make it more effective? How can I get the number of libs when it's not in array like brackets []?

Jaros
  • 27
  • 5
  • _“How can I get the number of libs when it's not in array like brackets []?”_ — Doesn’t your code try to find which key has the app `433340`? Why do you need the length? – Sebastian Simon Feb 03 '23 at 08:59
  • @SebastianSimon to loop though all the libs and find the corresponding path for the appID – Jaros Feb 03 '23 at 09:01
  • So you don’t actually need the length as part of your results? – Sebastian Simon Feb 03 '23 at 09:01
  • @SebastianSimon no, i don't – Jaros Feb 03 '23 at 09:02
  • 1
    It’s `Object.assign([], json.libraryfolders).filter(({ apps }) => Object.hasOwn(apps, "433340")).map(({ path }) => path)`. Alternatively, replace `Object.assign([], json.libraryfolders)` by `Object.values(json.libraryfolders)`. – Sebastian Simon Feb 03 '23 at 09:08

0 Answers0