Skip to main content
Participant
June 3, 2008
Question

[VB, CS3] How to place images using wildcards in filenames

  • June 3, 2008
  • 1 reply
  • 1086 views
Dear all,

Can anyone think of a way to place an image using a wildcard in the filename?

I can place the image fine if the complete filename is known, but what if the filename changes from day to day? - eg it could be House1234.tif for one document then House56r.tif for another. So I'd like to place House*.tif sort of thing. The files are in different folders, of which the path is known.

Any ideas?

Nigel
This topic has been closed for replies.

1 reply

Peter Kahrel
Community Expert
Community Expert
June 4, 2008
Get the contents of the whole folder in an array, then you can check each item to see if it matches some criterium. In Javascript (VB should be similar):
function find_file (dir, mask)

{
var f = Folder (dir).getFiles ('*.*');
for (var i = 0; i < f.length; i++)
if ( // compare f.name and mask here
return f;
}


This returns the first file in "dir" that matches "mask".

Peter
Jeremy bowmangraphics
Inspiring
May 16, 2019

I found this very helpful, thanks!

I scan the crossword every day and use a script to place it in InDesign, create a matching grid and so on, to do the crossword on screen. I wanted to use the scanner's default choice of folder and filename, which is something like "15-05-2019_103515.jpg" (from today's date + time). Although I didn't use a wildcard in my mask, I used the slice method to remove all but the date.

Community Expert
May 16, 2019

Hi Jeremy,

method getFiles() supports a filter function as well.

var myFilteredFilesArray = myFolder.getFiles

(

function( file )

        {

            if

            (

                file instanceof File

                &&

                file.name.match( /* testForSuffixRegExp or whatever you like */ )

                &&

                !file.hidden

            )

            return true

        }

);

Hope, you'll get the idea.

Regards,
Uwe