• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

New Here ,
Jun 03, 2008 Jun 03, 2008

Copy link to clipboard

Copied

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
TOPICS
How to , Scripting

Views

828

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 04, 2008 Jun 04, 2008

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 16, 2019 May 16, 2019

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 16, 2019 May 16, 2019

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 16, 2019 May 16, 2019

Copy link to clipboard

Copied

Hi Uwe,

That looks very useful too, thanks very much! I'm sure I'll use that approach in future. For what it's worth, here's the code I was using before I decided the slice method was easier:

var myRegex = new RegExp(myYear + "-" + myMonth + "-" + myToday + "_\\d{6}\\.jpg");

var myFile = findFile("Macintosh HD/Users/jeremy/Pictures", myRegex);

myPage.place(myFile, [36,36]);

function findFile(myFolder, myRegex) {

    var myFiles = Folder(myFolder).getFiles("*.*");

    for (var i = 0; i < myFiles.length; i++) {

        if (myFiles.name.match(myRegex)) return (myFiles);

        }

    }

Jeremy

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 16, 2019 May 16, 2019

Copy link to clipboard

Copied

LATEST

(Works beautifully too, by the way — thanks again!)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines