# Problems with chdir

**URL:** https://community.freefem.org/t/problems-with-chdir/902
**Category:** General Discussion
**Created:** [April 9, 2021, 3:53pm UTC](https://community.freefem.org/t/problems-with-chdir/902 "2021-04-09T15:53:16Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![RaMattoso](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/ramattoso/32/499_2.png) [@RaMattoso](https://community.freefem.org/u/RaMattoso)
#### Post date: [April 9, 2021, 3:53pm UTC](https://community.freefem.org/t/problems-with-chdir/902/1 "2021-04-09T15:53:16Z")

</div>

Hello fellows,

I’m new using FreeFeem, but I think the thing I’m trying to do is so simple.  
The code is

```
exec("mkdir result");
exec("chdir result");
	ofstream teste("teste.txt");
	teste << "hello World!";
exec("cd ..");

```

For some reason, it is not working. My expectation of this code is

1. Create the folder result
2. Enter the folder result
3. create teste.txt and write “hello World!” in it.
4. Get back to the initial directory.

But, it create the “teste.txt” file inside original folder. I can’t understand why.  
There is no compiling error. I don’t know.

I used “cd” instead of “chdir”, but no success either.

Please help. I guess is something very dumb, but I can’t figure what it is.  
Thanks.

---

<div class="post-metadata">

### Author: ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)
#### Post date: [April 9, 2021, 4:42pm UTC](https://community.freefem.org/t/problems-with-chdir/902/2 "2021-04-09T16:42:34Z")

</div>

Each `exec` will spawn a new and independent process, so it’s wrong to expect that after `exec("chdir result");`, any other `exec` calls will have a working directory set to `result`.

---

<div class="post-metadata">

### Author: ![RaMattoso](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/ramattoso/32/499_2.png) [@RaMattoso](https://community.freefem.org/u/RaMattoso)
#### Post date: [April 9, 2021, 5:07pm UTC](https://community.freefem.org/t/problems-with-chdir/902/3 "2021-04-09T17:07:34Z")

</div>

thank you for the answer.

Do you know how can I fix the code, in order to work properly?

thanks again

---

<div class="post-metadata">

### Author: ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)
#### Post date: [April 9, 2021, 5:12pm UTC](https://community.freefem.org/t/problems-with-chdir/902/4 "2021-04-09T17:12:57Z")

</div>

```auto
exec("mkdir result ");
	ofstream teste("result/teste.txt");
	teste << "hello World!";

```

---

<div class="post-metadata">

### Author: ![RaMattoso](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/ramattoso/32/499_2.png) [@RaMattoso](https://community.freefem.org/u/RaMattoso)
#### Post date: [April 9, 2021, 5:15pm UTC](https://community.freefem.org/t/problems-with-chdir/902/5 "2021-04-09T17:15:59Z")

</div>

THANK YOU SO MUCH!  
I tried so many formats but never this one.
