Subscribe Bookmark RSS Feed

How to eliminate subfolders from being included in a batch import

andyphillips0

New Contributor

Joined:

Sep 21, 2016

I am jusing JMP 9.0.3 and using a script to execute a batch import of csv files from a designated folder.   I am using the "Pick Directory" command to store the selected directory and the  "Files In Directory" command to store the file names in that directory.   I then loop through the files in a For Loop.   The problem is that in some of the directories there are sub-directories and the script does not ignore these and consequently aborts.  Is there a way to limit the array that results from the "Files in Directory" command to only the files in that directory and ignore any sub-directories?

Thanks,

Andy

1 ACCEPTED SOLUTION

Accepted Solutions
Solution

Hello,

maybe if you only look  for the extension of the file in your loop you can avoid issue. I don't know if it can help with JMP9.

For( fnb = 1, fnb <= NBFILES2, fnb++,  

 

If( Ends With( files[fnb], ".csv" ),

<your script>)

);

Jerome

3 REPLIES
Solution

Hello,

maybe if you only look  for the extension of the file in your loop you can avoid issue. I don't know if it can help with JMP9.

For( fnb = 1, fnb <= NBFILES2, fnb++,  

 

If( Ends With( files[fnb], ".csv" ),

<your script>)

);

Jerome

andyphillips0

New Contributor

Joined:

Sep 21, 2016

Thanks Jerome,

Yes this works fine.  I was pursuing a similar solution, but your code is a bit more elegant than what I came up with.   Thanks for the suggestion! 

Andy

msharp

Super User

Joined:

Jul 28, 2015

I know I'm late, but a more robust solution is to simply check if the file is a file:

dir = Pick Directory();

files = Files In Directory(dir);

for(i=1, i<=nitems(files), i++,

       if(isFile(dir || files[i]),

              print("File")

       ,

              print("Sub Directory")

       );

);


I'm not 100% positive the Is File() operator is available in JMP 9, but seeing the Pick Directory and Files In Directory are, I'd assume so.