# path exists

**URL:** <https://forum.hdfgroup.org/t/path-exists/2602>\
**Category:** Hdf-forum archives\
**Created:** [July 8, 2012, 11:02am UTC](https://forum.hdfgroup.org/t/path-exists/2602 "2012-07-08T11:02:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Philipp\_Kraus](https://forum.hdfgroup.org/user_avatar/forum.hdfgroup.org/philipp_kraus/32/1654_2.png) [@Philipp\_Kraus](https://forum.hdfgroup.org/u/Philipp_Kraus)\
**Post date:** [July 8, 2012, 11:02am UTC](https://forum.hdfgroup.org/t/path-exists/2602/1 "2012-07-08T11:02:13Z")

</div>

Hello,

I'm a little bit confused, because I run into sematic errors to check of a path / object exists in a HDF file.

I'm using at the moment within a CXX class the call H5Lexists( m\_file.getId(), mypath.c\_str() ), but in the documentation I  
have found ( [http://www.hdfgroup.org/HDF5/doc/RM/RM\_H5L.html#Link-Exists](http://www.hdfgroup.org/HDF5/doc/RM/RM_H5L.html#Link-Exists) ) that I must iterate over all pathes.  
I have found also the [http://www.hdfgroup.org/HDF5/doc/HL/RM\_H5LT.html#H5LTpath\_valid](http://www.hdfgroup.org/HDF5/doc/HL/RM_H5LT.html#H5LTpath_valid) path\_validate call  
but I can not create a working example.  
I'm using the 1.8.9 version of the library.

I would like to check if a absolut path exists in the file / point to an existing object. My path shows something like  
/mygroup1/mygroup2/dataset1 so the call should be return true if exist, and false if not. I don't use relative pathnames  
IMHO I have used the H5Lexists(m\_file.getId(), "/mygroup1/mygroup2/dataset1") call but it returns also true, if the path  
does not exists.  
I would like check, that the full path (all items) exists, only all items exsist, I want return true-

Which is the correct way to do this?

Thanks

phil

---

<div class="post-metadata">

**Author:** ![brtnfld](https://forum.hdfgroup.org/user_avatar/forum.hdfgroup.org/brtnfld/32/1444_2.png) [@brtnfld](https://forum.hdfgroup.org/u/brtnfld)\
**Post date:** [July 10, 2012, 3:42am UTC](https://forum.hdfgroup.org/t/path-exists/2602/2 "2012-07-10T03:42:27Z")

</div>

H5LTpath\_valid will tell you if the path exists. For your case it would be:

htri\_t path\_valid = H5LTpath\_valid(file\_id,"/mygroup1/mygroup2/dataset1",FALSE)

(side note: Are you saying the above path does actually not exists and therefore should return FALSE?)

This would check if all the links exists. What error are you having in your working example when using H5LTpath\_valid? Different test cases can be found in hl/test/test\_lite.c in the source if you need to look at some example use cases.

> **···**
>
> On 2012-07-08 07:02, Philipp Kraus wrote:
> 
> > Hello,
> > 
> > I'm a little bit confused, because I run into sematic errors to check  
> > of a path / object exists in a HDF file.
> > 
> > I'm using at the moment within a CXX class the call H5Lexists(  
> > m\_file.getId(), mypath.c\_str() ), but in the documentation I  
> > have found (  
> > [http://www.hdfgroup.org/HDF5/doc/RM/RM\_H5L.html#Link-Exists](http://www.hdfgroup.org/HDF5/doc/RM/RM_H5L.html#Link-Exists) ) that I  
> > must iterate over all pathes.  
> > I have found also the  
> > [http://www.hdfgroup.org/HDF5/doc/HL/RM\_H5LT.html#H5LTpath\_valid](http://www.hdfgroup.org/HDF5/doc/HL/RM_H5LT.html#H5LTpath_valid)  
> > path\_validate call  
> > but I can not create a working example.  
> > I'm using the 1.8.9 version of the library.
> > 
> > I would like to check if a absolut path exists in the file / point to  
> > an existing object. My path shows something like  
> > /mygroup1/mygroup2/dataset1 so the call should be return true if  
> > exist, and false if not. I don't use relative pathnames  
> > IMHO I have used the H5Lexists(m\_file.getId(),  
> > "/mygroup1/mygroup2/dataset1") call but it returns also true, if the  
> > path  
> > does not exists.  
> > I would like check, that the full path (all items) exists, only all  
> > items exsist, I want return true-
> > 
> > Which is the correct way to do this?
> > 
> > Thanks
> > 
> > phil
> > 
> > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > Hdf-forum is for HDF software users discussion.  
> > Hdf-forum@hdfgroup.org  
> > [http://mail.hdfgroup.org/mailman/listinfo/hdf-forum\_hdfgroup.org](http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org)
