Rename File in File System

Hi there,
I would like to save a TIF file but with extension “.abc” instead of “.tif”.
I’m saving the TIF using fs.getFileForSaving(“”), but PS is clever and nevertheless saves it as MyFile.tif.

As workaround I’m trying to save the file as *.tif and rename it afterwards using the UXP API function renameEntry() using following code:

var MyFolder = await require('uxp').storage.localFileSystem.getFolder(); // User needs to select folder
var entry = await MyFolder.getEntry("MyFile.tif"); // Loads mentioned file as "entry"
await MyFolder.rename(entry, ""); // Renames the entry

If I debug that I can see that the first 2 lines are working well, and that “entry” properly contains the file “MyFile.tif”.
But the rename() itself does not do anything.

Does anyone have a idea what the problem could be? Do I need a “Session Token” here as well as for the saving?
Or maybe someone has an idea how to tell PS directly to save a file with a custom extension.

Kind Regards

Hi there,
final update on that:

Since the renameEntry() function is not yet available in the official PS version, I’ve now solved it using moveTo() within the same folder with renaming as workaround:

  var persistentFolderToken = await localStorage.getItem("persistent-token"); 
  var folder = await require('uxp').storage.localFileSystem.getEntryForPersistentToken(persistentFolderToken);
  var entry = await folder.getEntry("MyFile.tif"); 
  await entry.moveTo(folder, { newName: "", overwrite: true })

btw: there is a typo in the documentation:
it says

await someFile.moveTo(someFolder, {newName: 'novel.txt', {overwrite: true})

but should be

await someFile.moveTo(someFolder, {newName: 'novel.txt', overwrite: true})
1 Like