# User folder by getenv

**URL:** <https://iplug2.discourse.group/t/user-folder-by-getenv/322>\
**Category:** macOS\
**Created:** [27 February 2021 12:27 UTC](https://iplug2.discourse.group/t/user-folder-by-getenv/322 "2021-02-27T12:27:55Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![SKyZz](https://avatars.discourse-cdn.com/v4/letter/s/4491bb/32.png) [@SKyZz](https://iplug2.discourse.group/u/SKyZz)\
**Post date:** [27 February 2021 12:27 UTC](https://iplug2.discourse.group/t/user-folder-by-getenv/322/1 "2021-02-27T12:27:55Z")

</div>

Hello everyone:

For any plugin, there is a path to the presets folder (Win):

```
string presetPath = "\\Any1\\Any2\\Presets\\" + start + ".preset";

char presetPath[MAX_PATH];
HRESULT hr = SHGetFolderPathW(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, (LPWSTR)presetPath );
strcat(anyPath, presetPath.c_str());
ifstream file1(presetPath);

```

> C:\Users\test\Documents\Any1\Any2\Presets\start.preset

On Mac (doesn’t work):

```
  string preset_file = "/Users/" + (string)getenv("USER") + "/Any1/Any2/Presets/" + start + ".preset"
  ifstream filepr(preset_file);

  if (!filepr.is_open())
  {
      
  }
  else {
      
  }

```

> Users/test/Documents/Any1/Any2/Presets/start.preset

How to get the “User” folder on mac?? I will be glad to hear any arguments or examples.

---

<div class="post-metadata">

**Author:** ![olilarkin](https://yyz2.discourse-cdn.com/free1/user_avatar/iplug2.discourse.group/olilarkin/32/2_2.png) [@olilarkin](https://iplug2.discourse.group/u/olilarkin)\
**Post date:** [27 February 2021 16:17 UTC](https://iplug2.discourse.group/t/user-folder-by-getenv/322/2 "2021-02-27T16:17:24Z")

</div>

you can use UserHomePath () or SandboxSafeAppSupportPath() in IPlugPaths.h

---

<div class="post-metadata">

**Author:** ![stw](https://avatars.discourse-cdn.com/v4/letter/s/8e8cbc/32.png) [@stw](https://iplug2.discourse.group/u/stw)\
**Post date:** [27 February 2021 16:32 UTC](https://iplug2.discourse.group/t/user-folder-by-getenv/322/3 "2021-02-27T16:32:43Z")

</div>

Can’t try Olis suggestion right now so maybe it’s obsolete. Anyway…  
I save my data in a subfolder of the Application Support folder and get that by:

```
FSRef ref;
OSType folderType = kApplicationSupportFolderType;
char appdata[MAX_PATH];
FSFindFolder( kLocalDomain, folderType, kCreateFolder, &ref );
FSRefMakePath( &ref, (UInt8*)&appdata, MAX_PATH );

```

I didn’t try myself but guess you can get the User folder with ‘kCurrentUserFolderLocation’

---

<div class="post-metadata">

**Author:** ![SKyZz](https://avatars.discourse-cdn.com/v4/letter/s/4491bb/32.png) [@SKyZz](https://iplug2.discourse.group/u/SKyZz)\
**Post date:** [27 February 2021 16:55 UTC](https://iplug2.discourse.group/t/user-folder-by-getenv/322/4 "2021-02-27T16:55:49Z")

</div>

I made a stupid but working version:

```
char presets_file_path[PATH_MAX];

strcpy(presets_file_path, "/Users/");
strcat(presets_file_path, getenv("USER"));
strcat(presets_file_path, "/Documents/AAA/BBB/Presets/start.preset");

```

presets\_file\_path:

> /Users/user/Documents/AAA/BBB/Presets/start.preset

---

<div class="post-metadata">

**Author:** ![olilarkin](https://yyz2.discourse-cdn.com/free1/user_avatar/iplug2.discourse.group/olilarkin/32/2_2.png) [@olilarkin](https://iplug2.discourse.group/u/olilarkin)\
**Post date:** [27 February 2021 16:57 UTC](https://iplug2.discourse.group/t/user-folder-by-getenv/322/5 "2021-02-27T16:57:05Z")

</div>

This will break in audiounits on apple silicon in sandboxed hosts like Logic and Garageband. Most devs are going for ~/Music ~/Documents may also work, not sure

---

<div class="post-metadata">

**Author:** ![SKyZz](https://avatars.discourse-cdn.com/v4/letter/s/4491bb/32.png) [@SKyZz](https://iplug2.discourse.group/u/SKyZz)\
**Post date:** [27 February 2021 17:05 UTC](https://iplug2.discourse.group/t/user-folder-by-getenv/322/6 "2021-02-27T17:05:26Z")

</div>

I’m not sure if it’s appropriate to ask here, but the question is about the paths, for example, I open my VST plugin in the Reaper, how do I find out the path to the VST plugin and not the path to the executable file that my plugin opens, i.e. the Reaper. This is already what I need for debag so as not to break the new Apple Silicon((

That is, the moment is specified, whether there is a common function for both operating systems?

---

<div class="post-metadata">

**Author:** ![olilarkin](https://yyz2.discourse-cdn.com/free1/user_avatar/iplug2.discourse.group/olilarkin/32/2_2.png) [@olilarkin](https://iplug2.discourse.group/u/olilarkin)\
**Post date:** [27 February 2021 17:06 UTC](https://iplug2.discourse.group/t/user-folder-by-getenv/322/7 "2021-02-27T17:06:35Z")

</div>

PluginPath(), but I am not sure it is reliable

---

<div class="post-metadata">

**Author:** ![SKyZz](https://avatars.discourse-cdn.com/v4/letter/s/4491bb/32.png) [@SKyZz](https://iplug2.discourse.group/u/SKyZz)\
**Post date:** [27 February 2021 17:13 UTC](https://iplug2.discourse.group/t/user-folder-by-getenv/322/8 "2021-02-27T17:13:29Z")

</div>

> [@olilarkin](#):
>
> PluginPath()

At the moment, this is what it looks like for me (win):

```
char plugin_path[1024];
uint32_t size = sizeof(plugin_path);
_NSGetExecutablePath(plugin_path, &size);

```

so I have to test all the options

---

<div class="post-metadata">

**Author:** ![SKyZz](https://avatars.discourse-cdn.com/v4/letter/s/4491bb/32.png) [@SKyZz](https://iplug2.discourse.group/u/SKyZz)\
**Post date:** [28 February 2021 12:06 UTC](https://iplug2.discourse.group/t/user-folder-by-getenv/322/9 "2021-02-28T12:06:17Z")

</div>

@olilarkin

For reference, maybe it will help someone.  
About: Get the self path (not executable app)

This [Function for mac](https://developer.apple.com/documentation/applicationservices/1501092-getprocessbundlelocation?changes=lates_7&language=objc) is equivalent to [WIN32 Api function](https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-getmodulefilenamea).

This code gets an executable app path

```
char plugin_path[1024];
uint32_t size = sizeof(plugin_path);
_NSGetExecutablePath(plugin_path, &size);

```

 ![Screen Shot 2021-02-28 at 14.44.01](https://global.discourse-cdn.com/free1/uploads/iplug2/original/1X/6a846ae56b89b19f23f738d90b8dfd315a35d4e6.png)

---

<div class="post-metadata">

**Author:** ![sstillwell](https://yyz2.discourse-cdn.com/free1/user_avatar/iplug2.discourse.group/sstillwell/32/69_2.png) [@sstillwell](https://iplug2.discourse.group/u/sstillwell)\
**Post date:** [22 April 2021 00:51 UTC](https://iplug2.discourse.group/t/user-folder-by-getenv/322/10 "2021-04-22T00:51:25Z")

</div>

This is way late, but if you’re looking for the home directory and find that it doesn’t get sandboxed, you can use getenv(“HOME”) - that should be valid on any \*nix OS.

For Windows it should be getenv(“USERPROFILE”)

Scott
