LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

get file visibility info on Mac

Is the a way to determine the visibility of a file on Mac OSX?

 

I have a vi to search a folder for the newest file but I want to limit it to visible files only.

 

Thanks!

0 Kudos
Message 1 of 3
(1,854 Views)

That's actually an amazingly complex question. 🙂

The underlaying unix file system doesn't really know the concept of a hidden file attribute like on Windows. On Unix any file or folder starting with a . (point) is considered invisible as far as the normal ls command on the command line is concerned but that's it. The standard Posix file API in the C runtime has no concept of hidden files at all.

 

The Finder in MacOS did have a hidden file attribute so Apple had to find a way to implement that for the MacOS X Finder. They did that with the attrlist facility which is an extra functionality in the BSD C runtime to access arbitrary metadata for file objects on filesystems that support it. The setattrlist() and getattrlist() API is however kind of complicated to use from LabVIEW through a Call Library Node.

 

There is another C runtime API chflags() that allows to set a 32 bit value that internally will use setattrlist() to change the flags attribute for the specified file object. The query of that flag value is through the standard stat() function in the C runtime API as Apple has extended the returned structure to contain this 16 bit value.

 

So you would basicially have to setup a Call Library node to interface to libc.so and configure a function with the name stat and two parameters.

 

return value: Numeric, int32

1st parameter: String, C string pointer

2nd Parameter: Adapt to Type

 

The first paramter has to be a Posix file path (that is the native format for 64-bit LabVIEW so the standard Path to String will work, but 32-bit LabVIEW uses HFS paths so you need to find the Utility function that converts a LabVIEW path into a Posix string.

 

Then you have to create the cluster for the second parameter.

 

     struct stat {
         dev_t    st_dev;    /* size 4, device inode resides on */
         int32_t  dummy;     /* size 4, alignment filler
         ino_t    st_ino;    /* size 8, inode's number */
         mode_t   st_mode;   /* size 2, inode protection mode */
         nlink_t  st_nlink;  /* size 2, number of hard links to the file */
         uid_t    st_uid;    /* size 4, user-id of owner */
         gid_t    st_gid;    /* size 4, group-id of owner */
         dev_t    st_rdev;   /* size 4, device type, for special file inode */
         time_t   st_atimesec;  /* size 8, time of last access */
         u_long   st_atimensec; /* size 4, nano seconds of last access */
         int32_t  st_atimefill; /* size 4, filler */
         time_t   st_mtimesec;  /* size 8, time of last modification */
         u_long   st_mtimensec; /* size 4, nano seconds of last modification */
         int32_t  st_mtimefill; /* size 4, filler */
         time_t   st_ctimesec;  /* size 8, time of last status change */
         u_long   st_ctimensec; /* size 4, nano seconds of last status change */
         int32_t  st_ctimefill; /* size 4, filler */
         off_t    st_size;   /* size 8, file size, in bytes */
         quad_t   st_blocks; /* size 8, blocks allocated for file */
         u_long   st_blksize;/* size 4, optimal file sys I/O ops blocksize */
         u_long   st_flags;  /* size 4, user defined flags for file */
         u_long   st_gen;    /* size 4, file generation number */
     };

 

 

The st_flags in there contains the following Mac OS X extended flags:

 

UF_HIDDEN    0x00008000

 

 

You will have to decide yourself if you also want to check the last file path element to start with a dot and treat it as hidden file or folder too.

Rolf Kalbermatter
My Blog
0 Kudos
Message 2 of 3
(1,822 Views)

Thanks for the detailed reply. I had no idea how complex the solution to my request was!

 

I'm no maven, so much of what you're saying is Greek to me. I've run across Call Library Node before but have only used what others have set up. Reading through your response, I'm having trouble figuring out how to go about this. For example, you mention libc.so, but I can't find that. Where should I look for that? Would it be possible for you to post an example vi?

 

Thanks again, I really appreciate the help.

0 Kudos
Message 3 of 3
(1,766 Views)