Search Unity

Application.peristentDataPath - how to clean up and maintain

Discussion in 'Editor & General Support' started by mattbrandmm, Jun 20, 2019.

  1. mattbrandmm

    mattbrandmm

    Joined:
    Jun 5, 2018
    Posts:
    90
    Hey all! I am working on a project that will store JSON files that will be keyed by a user ID and a version of the file in Application.persistentDataPath. One thing I am unsure of is how to clean up the old files, in order to have the storage not grow out of control on the device.

    So, for example, if the file name testConfig, the userID == xyz and the version is 1.1, I would store this file as:
    testConfig-xyz-1.1.

    When version 1.2 comes out, it would then store:
    testConfig-xyz-1.2

    This is done so that different users can have different config files.

    How do I clean up the old versions? Is there a way using Application.perisistentDataPath to see the contents in the directory? Is there a way to make subfolders in that location, so that the subfolder could be removed entirely?

    Any other ideas?
     
  2. grizzly

    grizzly

    Joined:
    Dec 5, 2012
    Posts:
    357
  3. mattbrandmm

    mattbrandmm

    Joined:
    Jun 5, 2018
    Posts:
    90
    OK thanks @grizzly that should work!