Skip to main content
sunilg33
Known Participant
April 2, 2019
Answered

How do i delete multiple files except a single file in it.

Hi  i have a situation something like, shown below


i have a folder called Export inside the 4 files


Export /

a.mxf

b.mxf

c.mxf

d.mxf

(4 files inside Export/).

Question:  i want to delete every files inside export folder except (c.mxf) with jsx. how can i do that ?

This topic is closed to new replies. Start a new post to keep the conversation going.
Manan JoshiCorrect answer
Community Expert
April 2, 2019

If you already have the folder path you could run getFiles on the folder object and then run a loop over the returned array of paths deleting all the files that does not match your name criteria. I have created a code snippet based on mask function of getFiles, it should also work. I have not tested it but you can get an idea of what i am proposing as a solution, to tweak it if needed

function findFiles(f)

{

    if(f.displayName != "c.mxf")

    {

          f.remove()

          return true

    }

    return false

}

var f = new Folder("Path to your export folder")

var delFilePathList = f.getFiles(findFiles)

-Manan

-Manan

2 replies

Manan JoshiCommunity ExpertCorrect answer
Community Expert
April 2, 2019

If you already have the folder path you could run getFiles on the folder object and then run a loop over the returned array of paths deleting all the files that does not match your name criteria. I have created a code snippet based on mask function of getFiles, it should also work. I have not tested it but you can get an idea of what i am proposing as a solution, to tweak it if needed

function findFiles(f)

{

    if(f.displayName != "c.mxf")

    {

          f.remove()

          return true

    }

    return false

}

var f = new Folder("Path to your export folder")

var delFilePathList = f.getFiles(findFiles)

-Manan

Translate
-Manan
sunilg33
sunilg33Author
Known Participant
April 2, 2019

thanks alot Manan, it worked for me!!!!!!!!!!!

Translate