# How to make a new folder on HD

**URL:** https://discourse.processing.org/t/how-to-make-a-new-folder-on-hd/41864
**Category:** Beginners
**Created:** [April 28, 2023, 9:17pm UTC](https://discourse.processing.org/t/how-to-make-a-new-folder-on-hd/41864 "2023-04-28T21:17:20Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [April 28, 2023, 9:17pm UTC](https://discourse.processing.org/t/how-to-make-a-new-folder-on-hd/41864/1 "2023-04-28T21:17:21Z")

</div>

Hello all,

small question here.

How can i make a new folder on HD?

Tried

```auto
  File f1=new File("");
  if ( f1.mkDir ( sketchPath("")+"//"+"c1" ) ) {
    //
  }

```

or

```auto
  File f1=new File(sketchPath("")+"//"+"c1");
  if (f1.mkDir()) {
    //
  }

```

coming from [https://docs.oracle.com/en/java/javase/12/docs/api/java.base/java/io/File.html#mkdir()](https://docs.oracle.com/en/java/javase/12/docs/api/java.base/java/io/File.html#mkdir())

but something is missing…?

Thank you!

Chrisir

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [April 28, 2023, 9:28pm UTC](https://discourse.processing.org/t/how-to-make-a-new-folder-on-hd/41864/2 "2023-04-28T21:28:24Z")

</div>

> [@Chrisir](#):
>
> **mkDir()**

Reference link you’ve posted says it’s **mkdir()**! 🤓

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [April 28, 2023, 9:30pm UTC](https://discourse.processing.org/t/how-to-make-a-new-folder-on-hd/41864/3 "2023-04-28T21:30:32Z")

</div>

Thanks!!!

This seems to work:

```auto
  File f1=new File(sketchPath("")+"//"+"c1");
  if (f1.mkdir()) {
    //
  }

```

😉

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [April 28, 2023, 9:50pm UTC](https://discourse.processing.org/t/how-to-make-a-new-folder-on-hd/41864/4 "2023-04-28T21:50:52Z")

</div>

> [@Chrisir](#):
>
> `File f1=new File(sketchPath("")+"//"+"c1");`

Processing got more streamlined methods for paths like [**savePath()**](http://processing.github.io/processing-javadocs/core/processing/core/PApplet.html#savePath-java.lang.String-), [**sketchFile()**](http://processing.github.io/processing-javadocs/core/processing/core/PApplet.html#sketchFile-java.lang.String-) and others:

```auto
final String path = savePath("c1/someFile.txt");
println(path);
exit();

```

```auto
final File path = sketchFile("c1");
println(path);
println(path.mkdir());
exit();

```

---

<div class="post-metadata">

### Author: ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)
#### Post date: [April 29, 2023, 3:22am UTC](https://discourse.processing.org/t/how-to-make-a-new-folder-on-hd/41864/5 "2023-04-29T03:22:10Z")

</div>

On MacOS first example does nothing. Second example creates an empty folder, not a file.

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [April 29, 2023, 7:52am UTC](https://discourse.processing.org/t/how-to-make-a-new-folder-on-hd/41864/6 "2023-04-29T07:52:15Z")

</div>

On Windows both examples create a subfolder “c1/” if it doesn’t exist yet inside sketch’s folder.

---

<div class="post-metadata">

### Author: ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)
#### Post date: [April 29, 2023, 1:46pm UTC](https://discourse.processing.org/t/how-to-make-a-new-folder-on-hd/41864/7 "2023-04-29T13:46:06Z")

</div>

Hi,

I would recommend to use java.nio instead of [java.io](http://java.io) because of several advantages, especially wrt error handling. For creating files and directories,take a look here …

> **[Introduction to Java NIO2 File API | Baeldung](https://www.baeldung.com/java-nio-2-file-api)**
>
> A quick and practical guide to Java NIO2 File API

Cheers  
— mnse
