Getting error – folder doesn’t exist in Scriptable for iOS26


I’m trying to make a shortcut to delete some files with the help of Scriptable app in iOS26.

I want to search inside a specific folder (iCloud Drive > Images) for JPEGs & if found delete all of them whose creation date is 3 days earlier than current day ?

Below is the scriptable script to do so:

// TARGET FOLDER PATH
const folderPath = "Images"; // iCloud Drive > Images

// Get current date and subtract 3 days
const now = new Date();
const threshold = new Date(now.getTime() - 3 * 24 * 60 * 60 * 1000);

// Load files from folder
const fm = FileManager.iCloud();
const folder = fm.joinPath(fm.documentsDirectory(), folderPath);
const files = fm.listContents(folder);

let deleted = [];

for (let file of files) {
  const fullPath = fm.joinPath(folder, file);

  // Check if it's a JPEG
  if (file.toLowerCase().endsWith(".jpg") || file.toLowerCase().endsWith(".jpeg")) {
    const attrs = fm.getAttributes(fullPath);
    const created = attrs.creationDate;

    // Compare creation date
    if (created <= threshold) {
      fm.remove(fullPath);
      deleted.push(file);
    }
  }
}

// Show result
if (deleted.length > 0) {
  let msg = `Deleted ${deleted.length} JPEG(s):\n` + deleted.join("\n");
  await new Alert({ title: "Cleanup Complete", message: msg }).present();
} else {
  await new Alert({ title: "No Files Deleted", message: "No JPEGs older than 3 days found." }).present();
}

But getting error

ERROR MSG
loc

Code to list the folders accessible to Scriptable

const fm = FileManager.iCloud();
const root = fm.documentsDirectory();
const items = fm.listContents(root);

let folders = [];

for (let item of items) {
  const path = fm.joinPath(root, item);
  if (fm.isDirectory(path)) {
    folders.push(item);
  }
}

if (folders.length > 0) {
  let msg = "Folders Scriptable can access:\n" + folders.join("\n");
  await new Alert({ title: "iCloud Folders", message: msg }).present();
} else {
  await new Alert({ title: "No Folders Found", message: "Scriptable couldn't find any folders in iCloud Drive." }).present();
}const fm = FileManager.iCloud();
const root = fm.documentsDirectory();
const items = fm.listContents(root);

let folders = [];

for (let item of items) {
  const path = fm.joinPath(root, item);
  if (fm.isDirectory(path)) {
    folders.push(item);
  }
}

if (folders.length > 0) {
  let msg = "Folders Scriptable can access:\n" + folders.join("\n");
  await new Alert({ title: "iCloud Folders", message: msg }).present();
} else {
  await new Alert({ title: "No Folders Found", message: "Scriptable couldn't find any folders in iCloud Drive." }).present();
}

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img