Get list of PDF-files from folder to populate drop-down

Post Reply
User avatar
JimmyHartington
Member
Posts: 28
Joined: Tue Mar 22, 2011 7:38 am

Get list of PDF-files from folder to populate drop-down

Post by JimmyHartington »

Hi

I am creating a flow, where I start with a Submit Point.

And I would like to have the user fill out metadata.
One of them should be a dropdown of files from a folder on the Switch-Server.
The contents of the folder will only be pdfs but it the number of pdfs changes over time.

I tried to set the Data values of the dropdown to a script expresision (see code below), but SwitchClient just shows me a text-entry field. If I set values manually, then I get a dropdown.

Image

I hope somebody can help.

Code: Select all

var theDir = new Dir("D:\SB-S\kursussystem-v2\APPROVED");

var theEntries = theDir.entryList("*.pdf", Dir.Files, Dir.Name);

	var list = new Array;

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

		list.push(theEntries[i]);

	list;
loicaigon
Member
Posts: 147
Joined: Wed Jul 10, 2013 10:22 am

Re: Get list of PDF-files from folder to populate drop-down

Post by loicaigon »

Hi,
Not helping but your code just works fine onto my mac :S
User avatar
Terkelsen
Member
Posts: 126
Joined: Thu Sep 08, 2011 5:08 pm
Contact:

Re: Get list of PDF-files from folder to populate drop-down

Post by Terkelsen »

Hi Jimmy ;)
Try This:

var theDir = new Dir("D:\\SB-S\kursussystem-v2\APPROVED");

var theEntries = theDir.entryList("*.pdf", Dir.Files, Dir.Name);

var list = new Array;

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

list.push(theEntries);

list;


The extra backlash made all the difference for me.
User avatar
JimmyHartington
Member
Posts: 28
Joined: Tue Mar 22, 2011 7:38 am

Re: Get list of PDF-files from folder to populate drop-down

Post by JimmyHartington »

Terkelsen wrote:The extra backlash made all the difference for me.
Thanks to Erik to point me in the right direction.
I needed to use doublebackslash in the complete path. And then it worked.

I have added some extra-code to remove the extension of the filename.

Finished and working code:

Code: Select all

var theDir = new Dir("D:\\SB-S\\kursussystem-v2\\APPROVED");
var theEntries = theDir.entryList("*.pdf", Dir.Files, Dir.Name);
var list = new Array;
for (var i = 0; i < theEntries.length; i++)
  list.push(theEntries[i].substring(0, theEntries[i].lastIndexOf('.')));
 
list;
Post Reply