Page 1 of 1

Looping to pick up media files from a folder

PostPosted: Sun Oct 23, 2005 5:03 pm
by Thunder
Hi all

In migrating my solution from Filemaker to Servoy, I have got to stage z, the bit that I've been avoiding...

I have exported 3377 images from the original filemaker solution into a folder. These pictures are named by a combination of their record number (dhs 1234 and a unique id so, for eg, DHS 1234 234.jpg, DHS 1234 235.jpg, DHS 1234 236.jpg etc. (they were related pictures before and I figured that including the record id as the name would be helpful when relating later.)

I now need to write a method which will create a new record in the images database, go to my folder, get image 1 and put its name into a field, then create a new record, import image 2 and put its name into the field etc.

The plan is then to separate out the DHS 1234 from 234, 235, 236 etc. once the import is done

After this I can import ANOTHER table with the text data from the original filemaker images database and loop through from my newly imported servoy images form to pick up all the other data related to DHS 1234.

My question is, can anyone point me at an example or the right syntax for looping through, creating records and picking up image files for import into blobs in Servoy please...

Be very grateful for any help anyone can give.

Bevil

PostPosted: Sun Oct 23, 2005 5:46 pm
by ROCLASI
Hi Bevil,

The following code should point you in the right direction.

Code: Select all
// Get the folder to import from
var theFolder = plugins.file.showDirectorySelectDialog();

// Did we select something or not
if ( theFolder )
{
   // Get all the files according to the filter array (jpg and JPG)
   var theFolderContents = plugins.file.getFolderContents( theFolder,  ['jpg','JPG']);

   // Loop through the fetched array with files
   for ( var i = 0 ; i < theFolderContents.length ; i++ )
   {
      // extra check if this file is indeed a file and not a folder
      if ( theFolderContents[i].isFile() )
      {
         // Create a new record in the current form
         controller.newRecord();
         // put the image in the field
         myImageField = plugins.images.getImage(theFolderContents[i]);
      }
   }
}



Hope this helps.

PostPosted: Sat Oct 29, 2005 12:12 am
by Thunder
Thank you Robert