How to access path module?

I’m trying to find a usage example for the Path module (as documented in the UXP Javascript reference), specifically how to access it. I tried:


as well as


Neither did the job. If someone out there has had luck using this module I’d be super curious to find out how :slight_smile: Thanks in advance!

1 Like

According to @shuji, path variable can be used without any declaration.

const pathText = `file:/Users/username/Desktop/filename.txt` ;

const parentFolder = path.dirname(pathText) ;
console.log(parentFolder) ; // --> file:/Users/username/Desktop

const nameWithoutExtension = path.parse(pathText).name ;
console.log(nameWithoutExtension) ; // --> filename
1 Like

Here I made an example of how to get the directory, create a subfolder and save the active document with jpg extension.

  try {
      const path = app.activeDocument.path.replace(/\\[^\\]*$/, "")
      const Entrada = await fs.getEntryWithUrl(`file:${path}`); 

      const entries = await Entrada.getEntries();   
      let subfolder = entries.filter((entry) => entry.isFolder).find((subFolder) => === "SubFolder");
      if (!subfolder) {subfolder = await Entrada.createFolder("SubFolder");}
      newFileName =;
      var myFile = await subfolder.createFile(newFileName, { overwrite: true });
      let jpegOptions = {
          quality: 100,
          embedColorProfile: true
      app.activeDocument.saveAs.jpg(myFile, jpegOptions, true);
  } catch (err) {alert(err)}

You can get more details in this dicursion Save Batch Images with Dynamic Name in Photoshop UXP