Get names from a csv file

Hi All,
I really need help to create a script that does the things below.
I can write it using the old method, but I don’t have any idea how to -using UXP.

Below are the steps:

  1. Evaluate the names of all JPGs opened in Photoshop.
  2. List the JPG names in column B of a .csv file.
  3. Save those files as TIFF with a new naming taken from the column A of .csv file.

Basically I will already have an existing .csv file and column A is already filled with string data
Column B is still blank, but if i run the script, it should be filled with all the names of JPG files that are open in Photoshop.

Im currently starting with getFileForSaving() to read and write onto the csv file, but I couldnt make it work.

Any help would be greatly appreciated.

if you need to know how to read and write text data on UXP ,I think using fs module and path module helps your task.

const fsProvider = require('uxp').storage.localFileSystem;
const app = require('photoshop').app;
const fs = require("fs");
const readCsvFIle = async () => {  
  try {
    // select csv file through dialog
    const file = await fsProvider.getFileForOpening();
    // fsreadFile method reads inside of csv data 
    const r = await fs.readFile(file.nativePath, {encoding: "utf8"});
    //log shows you csv data as a type of string
    console.log(r);
    const dirname = path.dirname(file);
    // write new csv data here
    await fs.writeFile(path.join(dirname, "newdata.csv"),r + "something new,");
  } catch (e) {
    await app.showAlert(e);
  }
}

adding localFileSystem on manifest.json

    "requiredPermissions": {
        "localFileSystem": "fullAccess"
    },

fs module

path module

1 Like

@shuji
This works! Thank you very much!