Subscribe Bookmark RSS Feed

Check to see if a list is empty

lodey101

Community Trekker

Joined:

Oct 4, 2011

Hi there,

     This may be an easy question to answer but what I am trying to do is use JMP  to count the number of files contained within a specific directory and return a value of either 0 if none exist or the number of files.

I know that using the Files In Directory function will list the files contained as a list but what I want to do is convert this to a numerical value:

ie:


//set up raw dir


raw_dir = "C:\\My PhotoFilmStrips\";


_files = Files In Directory( raw_dir );



//show files


show(_files);



show( Type(_files), Is Empty(_files), Is Missing(_files), _files==Empty());


If I run the above script i get the following with a file contained within the raw directory:

Type(_files) = "List";

Is Empty(_files) = 0;

Is Missing(_files) = {0};

_files == Empty() = 0;

When the directory is empty I get:

Type(_files) = "Number";

Is Empty(_files) = 0;

Is Missing(_files) = 1;

_files == Empty() = .;

How can I make use of the Is Missing variable - ie if it is 1 then assign the number to a variable like tt=0 and when it the Is Missing variable is 0 then tt=1

Any help would be appreciated

Rgds

Colin

2 REPLIES
ms

Super User

Joined:

Jun 23, 2011

In JMP 10 and 11 an empty directory gives an empty list, not a missing value and I would thus expect Is Missing() to return 0. Strangely, If applied to an empty list Is Missing() returns an empty list, not 0 or 1 that is the expected output from a boolean function. I am not sure how it works in JMP 9.


I suggest you use N Items() instead. For example:

tt=(nitems(_files)>0);

If using Is Missing() you can switch between 0 and 1 with the NOT operator, i.e. !Is Missing()

michael_jmp

Staff

Joined:

Jun 23, 2011

Is Missing() on an empty list will return an empty list, because it is operating on each element of a list.  If the list is empty, there are no elements for Is Missing() to operate on, so it returns the empty list.  However, a better way to see this is the following example:

lst = {1,2,.,""};

ismissing(lst);

Michael Crotty
Sr Statistical Writer
JMP Development