Looping to pick up media files from a folder

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

Looping to pick up media files from a folder

Postby Thunder » Sun Oct 23, 2005 5:03 pm

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
Thunder
 
Posts: 431
Joined: Thu Apr 24, 2003 10:33 am
Location: London

Postby ROCLASI » Sun Oct 23, 2005 5:46 pm

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.
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Postby Thunder » Sat Oct 29, 2005 12:12 am

Thank you Robert
Thunder
 
Posts: 431
Joined: Thu Apr 24, 2003 10:33 am
Location: London


Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 9 guests

cron