# Sys.getCwd returns empty string while targeting CPP

**URL:** <https://community.haxe.org/t/sys-getcwd-returns-empty-string-while-targeting-cpp/1886>\
**Category:** Haxe\
**Tags:** haxe-cpp\
**Created:** [July 10, 2019, 7:41am UTC](https://community.haxe.org/t/sys-getcwd-returns-empty-string-while-targeting-cpp/1886 "2019-07-10T07:41:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tarloing](https://community.haxe.org/user_avatar/community.haxe.org/tarloing/32/934_2.png) [@Tarloing](https://community.haxe.org/u/Tarloing)\
**Post date:** [July 10, 2019, 7:41am UTC](https://community.haxe.org/t/sys-getcwd-returns-empty-string-while-targeting-cpp/1886/1 "2019-07-10T07:41:09Z")

</div>

Hello,  
I’m on a project in which I need to get the user’s current working directory. I tried:

- sys.FileSystem.absolutePath(".")
- Sys.programPath() / Sys.executablePath()
- Sys.getCwd()

```haxe
public static function main() {
	trace(Sys.getCwd());
}

```

I tried with a little project with just a Main.hx and this code snippet is getting well in haxe but not in CPP. In CPP, it returns an empty string.

After some research in forums, I found a “solution” using macros but this one keep the cwd at compilation. This is not what we intend because the program needs to access distributed resources.

```haxe
public static function main() {
	trace(cwd());
}
	
public static macro function cwd():haxe.macro.Expr.ExprOf<String> {
	return macro $v{Sys.getCwd()};
}

```

If you have any solutions to make Sys.getCwd() work in CPP.

Thanks

---

<div class="post-metadata">

**Author:** ![ibilon](https://community.haxe.org/user_avatar/community.haxe.org/ibilon/32/13_2.png) [@ibilon](https://community.haxe.org/u/ibilon)\
**Post date:** [July 10, 2019, 7:44am UTC](https://community.haxe.org/t/sys-getcwd-returns-empty-string-while-targeting-cpp/1886/2 "2019-07-10T07:44:37Z")

</div>

`trace(Sys.getCwd());` correctly print the cwd for me.

Which version of haxe and hxcpp do you have?  
What is your OS?  
Does the cwd contains a special/non ascii character?

---

<div class="post-metadata">

**Author:** ![Tarloing](https://community.haxe.org/user_avatar/community.haxe.org/tarloing/32/934_2.png) [@Tarloing](https://community.haxe.org/u/Tarloing)\
**Post date:** [July 10, 2019, 8:22am UTC](https://community.haxe.org/t/sys-getcwd-returns-empty-string-while-targeting-cpp/1886/3 "2019-07-10T08:22:24Z")

</div>

I use haxe 4.0.0-rc.2+77068e10c, hxcpp 4.0.8  
My OS is Windows.  
The cwd does not contains special/non ascii characters but it could have some with our clients.
