Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

generic directory user locations

Discussion in 'Editor & General Support' started by okkal11, Jun 29, 2018.

  1. okkal11

    okkal11

    Joined:
    Jul 15, 2013
    Posts:
    16
    Hey,

    I need to find c:/SOMEUSER/SOMEFOLDER

    Is there a generic way to locate SOMEFOLDER that will work regardless of username?

    Thanks :)

    Kal.
     
  2. verybinary

    verybinary

    Joined:
    Sep 23, 2015
    Posts:
    373
    I would hope for unitys sake that unity doesn't have access to files like that?
    could you not create this folder in the directory the game files are stored in?
     
  3. okkal11

    okkal11

    Joined:
    Jul 15, 2013
    Posts:
    16
    Nothing mallicious at all, most games save data to c:/USERNAME/documents/GAMENAME - thats why i need to direct to that location regardless of username :)
     
  4. verybinary

    verybinary

    Joined:
    Sep 23, 2015
    Posts:
    373
    you could try loading "./somefolder"
    the . is cli for "my current directory"
     
  5. stillwwater

    stillwwater

    Joined:
    Feb 8, 2016
    Posts:
    11
    Check out Application.persistentDataPath for a safe (cross-platform) location to store save files.

    I know a lot of games use C:/USERNAME/documents/ but I think a lot of users would prefer not having their documents folder cluttered :)
     
  6. okkal11

    okkal11

    Joined:
    Jul 15, 2013
    Posts:
    16
    Yeah i know about persistantdatapath, but i need the other functionallity :) thanks tho

    Windows uses something like "%userprofile%\documents" - not sure it will work with unity tho, will try when im back at work :) Thanks all
     
  7. stillwwater

    stillwwater

    Joined:
    Feb 8, 2016
    Posts:
    11
    In that case you can try using
    System.Environment.GetEnvironmentVariable("USERPROFILE")
    or if you're using C# 4.0 you can also use
    System.Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)
    .

    Not sure if this works for platforms other than Windows though!
     
    okkal11 likes this.
  8. okkal11

    okkal11

    Joined:
    Jul 15, 2013
    Posts:
    16
    I will defo try that out, thanks Stillwater!
     
  9. okkal11

    okkal11

    Joined:
    Jul 15, 2013
    Posts:
    16
    T
    Finally got around to try it out (swamped at work hehe) and that worked perfectly, thanks so much bro