
At 10:52 AM 9/10/2004, Martin wrote:
My real life need is that in Windows there are some files in the root directory that you can't query the attributes for. Haven't checked the exact conditions but is_directory will throw for me when iterating over c:\.
pagefile.sys is one case. There may be others. That does seem like a practical example; I know I've run into it. OK, assume we want to add is_accessible(). What are the specifications? Perhaps: Returns: true if exists(ph) and the attributes of ph can successfully be queried. Note: Certain files or directories exist, but the user may not have the proper permissions to access them. For example, on Windows, ordinary users do not have permission to access the attributes of pagefile.sys. Thus in the directory containing pagefile.sys, exists("pagefile.sys") is true but is_accessible("pagefile.sys") is false. An attempt to query the attributes, such as is_directory("pagefile.sys") would throw an exception, which can be avoided by checking is_accessible("pagefile.sys"). The code might look something like: for (directory_iterator itr(mypath); itr != directory_iterator(); ++itr) { // ignore directories if (!is_accessable(*itr) || is_directory(*itr)) continue; ... Comments? --Beman