Choose Language Hide Translation Bar
Highlighted

How to eliminate subfolders from being included in a batch import

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
Highlighted
ptijerome
Level II

Re: How to eliminate subfolders from being included in a batch import

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

View solution in original post

3 REPLIES 3
Highlighted
ptijerome
Level II

Re: How to eliminate subfolders from being included in a batch import

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

View solution in original post

Highlighted

Re: How to eliminate subfolders from being included in a batch import

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

Highlighted
msharp
Super User

Re: How to eliminate subfolders from being included in a batch import

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.

Article Labels

    There are no labels assigned to this post.