Skip to main content
Inspiring
March 12, 2020
Question

If I create a folder on the desktop can't I remove it?

  • March 12, 2020
  • 1 reply
  • 464 views

If I create a folder on my desktop can't I remove/delete it? Alternatively can I just delete a file or folder on my desktop from an InDesign script or do I need to create it and have it assigned to a variable?

 

var myFolder = new Folder("~/Desktop/tempFiles");
myFolder.create();


myFolder.remove();

 

    This topic has been closed for replies.

    1 reply

    Community Expert
    March 12, 2020

    Hi David,

    you can only remove empty folders.

    Does your folder contain files or subfolders?

     

    See:

    https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Folder.html#d1e7645__d1e8359

     

    Folder object

    Boolean remove ()

     

    Deletes the folder associated with this object from disk immediately, without moving it to the system trash.

    Folders must be empty before they can be deleted. Does not resolve aliases; instead, deletes the referenced alias or shortcut file itself. Returns true if the file was successfully removed. IMPORTANT: Cannot be undone. It is recommended that you prompt the user for permission before deleting.

     

    Regards,
    Uwe Laubender

    ( ACP )

    Inspiring
    March 12, 2020

    So this is the thing. When I had a single image I created and then removed it worked. myFile.remove();

    but as soon as I wrapped it up in a function myFile no longer worked.

    function pdfExportFunc(P1, P2){
    pageRange = P1;
    var myFile = new File("~/Desktop/tempFiles/"+P2+".pdf");
    app.activeDocument.exportFile(ExportFormat.pdfType, myFile, false);
    }
    pdfExportFunc(pageNumbera, "mockUPTempFile_01");
    pdfExportFunc(pageNumbera, "mockUPTempFile_02");
    pdfExportFunc(pageNumbera, "mockUPTempFile_03");

     

    Is there a way to delete those created by this function?