Skip to main content
June 25, 2012
Question

Folder.getFiles Multiple Filters Mask

  • June 25, 2012
  • 4 replies
  • 14264 views

Hi all,

Folder.getFiles (".*") ... in this case it will get all types of files

Folder.getFiles (".jpg") ... in this case it will get all files with .jpg extension

... but how can I filter to get (for example) all files with ".jpg", " .tif" or ".eps" extension ?

ESTK help says: A mask string can also be the name of a function that takes a File or Folder object as its argument. It is called for each file or folder found in the search; if it returns true, the object is added to the return array.

Any idea of how to make such a function?

I will appreciate any help.

This topic has been closed for replies.

4 replies

Jongware
Community Expert
Community Expert
June 25, 2012

It depends on your operating system!

From a recent script of mine:

if (File.fs == "Windows")

pdfFile = Folder.myDocuments.openDlg( 'Load PDF document', "Adobe PDF:*.pdf,All files:*.*", false);

else

pdfFile = Folder.myDocuments.openDlg( 'Load PDF document', function(file) { return file instanceof Folder || (!(file.hidden) && (file.name.match(/\.pdf$/i) || file.type == "PDF ")); }, false );

(Note the second part for OS X. Since I know the 'type' of a PDF is "PDF " -- including a space at the end --, this ought to be enough to discern PDFs. However, it's possible the OS File Type might be 'unknown' (for example, with a downloaded file), so I test the extension anyway.)

bagonterman
Inspiring
July 18, 2013

What would you use to just return the file name and not the full name?

bagonterman
Inspiring
July 18, 2013

Folder.getFiles(File.name ); but this does not work. Any ideas?

Inspiring
June 25, 2012

You can use a regular expression…

var pics = Folder.desktop.getFiles( /\.(epsf?|jpe?g|tiff?)$/i );

$.write( pics.join( '\r' ) );

Inspiring
June 25, 2012

Use regex.

Folder.getFiles(/.+\.(?:gif|jpe?g|[ew]mf|eps|tiff?|psd|pdf|bmp|png)$/i);

SumitKumar
Inspiring
December 12, 2021

Hi, 

 

Is this work on Macintosh OS?

 

Regards,

-Sumit
Peter Kahrel
Community Expert
Community Expert
December 13, 2021

Try it and you'll find out. You're not going to break anything.

 

P.

Inspiring
June 25, 2012

Send an array:

Folder.getFiles (["Files:*.doc;*.docx;*.rtf"])

Edit: That should be:

Folder.getFiles ("Please select files",["Files:*.doc;*.docx;*.rtf"])