How to make a new folder on HD

Hello all,

small question here.

How can i make a new folder on HD?

Tried

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

or

  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()

but something is missing…?

Thank you!

Chrisir

Reference link you’ve posted says it’s mkdir()! :nerd_face:

1 Like

Thanks!!!

This seems to work:

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

:wink:

Processing got more streamlined methods for paths like savePath(), sketchFile() and others:

final String path = savePath("c1/someFile.txt");
println(path);
exit();
final File path = sketchFile("c1");
println(path);
println(path.mkdir());
exit();
2 Likes

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

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

Hi,

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

Cheers
— mnse

1 Like