# How to use H5ocopy to copy a group with hard links

**URL:** <https://forum.hdfgroup.org/t/how-to-use-h5ocopy-to-copy-a-group-with-hard-links/8443>\
**Category:** HDF5 Library\
**Created:** [April 27, 2021, 7:56am UTC](https://forum.hdfgroup.org/t/how-to-use-h5ocopy-to-copy-a-group-with-hard-links/8443 "2021-04-27T07:56:13Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![sandhya.v250](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/s/bc79bd/32.png) [@sandhya.v250](https://forum.hdfgroup.org/u/sandhya.v250)\
**Post date:** [April 27, 2021, 7:56am UTC](https://forum.hdfgroup.org/t/how-to-use-h5ocopy-to-copy-a-group-with-hard-links/8443/1 "2021-04-27T07:56:13Z")

</div>

Hello,  
I am trying to copy the group “post” which is the symbolic link to csmexpl…so my expectation is when ever i copy the group path like post/constant i want it to copy the symbolic link too like csmexpl/constant…so can you please help me on this.(i am using C methods)  
Below is the image to illustrate  
 ![image%20(1)](https://hdf-discourse-1.s3.amazonaws.com/original/2X/2/2b5b9dc030e99a5e939e344c64853e2790cf28b8.png)

---

<div class="post-metadata">

**Author:** ![contact](https://forum.hdfgroup.org/user_avatar/forum.hdfgroup.org/contact/32/1067_2.png) [@contact](https://forum.hdfgroup.org/u/contact)\
**Post date:** [April 27, 2021, 9:20am UTC](https://forum.hdfgroup.org/t/how-to-use-h5ocopy-to-copy-a-group-with-hard-links/8443/2 "2021-04-27T09:20:57Z")

</div>

Hi @sandhya.v250,

If you are ok in using [HDFql](https://www.hdfql.com), you can make a (deep) copy of (link) `post` like the following in C:

```
#include "HDFql.h"
void main(int argc, char *argv[])
{
      hdfql_execute("COPY allinone_RESULT.erfh5 post TO allinone_RESULT.erfh5 post_copy");
}

```

Additional information can be found on section `6.4.13` of HDFql [reference manual](https://www.hdfql.com/resources/HDFqlReferenceManual.pdf).

---

<div class="post-metadata">

**Author:** ![sandhya.v250](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/s/bc79bd/32.png) [@sandhya.v250](https://forum.hdfgroup.org/u/sandhya.v250)\
**Post date:** [April 27, 2021, 9:44am UTC](https://forum.hdfgroup.org/t/how-to-use-h5ocopy-to-copy-a-group-with-hard-links/8443/3 "2021-04-27T09:44:06Z")

</div>

Thanks for your answer, i want to copy all the groups except multistate so each time i need to give a path to copy…It’s better if i get to use h5ocopy()

---

<div class="post-metadata">

**Author:** ![contact](https://forum.hdfgroup.org/user_avatar/forum.hdfgroup.org/contact/32/1067_2.png) [@contact](https://forum.hdfgroup.org/u/contact)\
**Post date:** [April 27, 2021, 10:07am UTC](https://forum.hdfgroup.org/t/how-to-use-h5ocopy-to-copy-a-group-with-hard-links/8443/4 "2021-04-27T10:07:33Z")

</div>

Ok - that’s a different requirement from the one stated in the beginning…

If you wish to copy all groups (stored in group `CSMEXPL`) except `multistate` into a group called `post`, then one way of doing this is as follows:

```
#include "HDFql.h"

void main(int argc, char *argv[])
{
    // declare variable
    char script[1024];

    // use (i.e. open) HDF5 file 'allinone_RESULT.erfh5'
    hdfql_execute("USE FILE allinone_RESULT.erfh5");

    // create new group 'post'
    hdfql_execute("CREATE GROUP post");

    // get all (sub)groups stored in group 'CSMEXPL'
    hdfql_execute("SHOW GROUP CSMEXPL/");

    // copy each (sub)group found in 'group 'CSMEXPL' (except (sub)group 'multistate') into group 'post'
    while(hdfql_cursor_next(NULL) == HDFQL_SUCCESS)
    {
        if (strcmp(hdfql_cursor_get_char(NULL), "multistate") != 0)
        {
            sprintf(script, "COPY CSMEXPL/%s TO post/%s", hdfql_cursor_get_char(NULL), hdfql_cursor_get_char(NULL));
            hdfql_execute(script);
        }
    }

    // close HDF5 file 'allinone_RESULT.erfh5'
    hdfql_execute("CLOSE FILE");
}

```

In addition, if you just wish to create symbolic (soft) links to groups (instead of copying these), just replace this line:

```
sprintf(script, "COPY CSMEXPL/%s TO post/%s", hdfql_cursor_get_char(NULL), hdfql_cursor_get_char(NULL));

```

with this:

```
sprintf(script, "CREATE SOFT LINK post/%s TO CSMEXPL/%s", hdfql_cursor_get_char(NULL), hdfql_cursor_get_char(NULL));

```

Hope this helps!

---

<div class="post-metadata">

**Author:** ![gheber](https://forum.hdfgroup.org/user_avatar/forum.hdfgroup.org/gheber/32/1919_2.png) [@gheber](https://forum.hdfgroup.org/u/gheber)\
**Post date:** [April 27, 2021, 1:53pm UTC](https://forum.hdfgroup.org/t/how-to-use-h5ocopy-to-copy-a-group-with-hard-links/8443/5 "2021-04-27T13:53:05Z")

</div>

To be honest, I don’t understand the question. Are you trying to copy groups or links?

> [@sandhya.v250](#):
>
> I am trying to copy the group “post” which is the symbolic link to csmexpl…

You are telling us that you want to copy the group `post`, but then you are telling us that that’s actually not a group but a symbolic link. A group is a collection of links. Copying a group means creating a new group that contains copies of the original group’s links (and attributes). Copying a link means something else. Which one would you like? G.

---

<div class="post-metadata">

**Author:** ![sandhya.v250](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/s/bc79bd/32.png) [@sandhya.v250](https://forum.hdfgroup.org/u/sandhya.v250)\
**Post date:** [May 3, 2021, 8:26am UTC](https://forum.hdfgroup.org/t/how-to-use-h5ocopy-to-copy-a-group-with-hard-links/8443/6 "2021-05-03T08:26:49Z")

</div>

Post is a hardlink to CSMEXPL group in the image.  
So when i copy the whole post group, the CSMEXPL should also need to be copied because it’s a hard link this is my requirement.  
Is there any copy or link property list flags to copy hard links as well. I tried all the flags but did not work.  
The following code copies only group

lcpl\_id = H5Pcreate(H5P\_LINK\_CREATE);  
status = H5Pset\_create\_intermediate\_group(lcpl\_id, 1);  
status = H5Ocopy(file\_id, “post”, file\_id\_two, “post”, H5P\_DEFAULT, lcpl\_id);  
I saw in specification that lcpl\_id has flags to copy hard links but i could not make it work

---

<div class="post-metadata">

**Author:** ![gheber](https://forum.hdfgroup.org/user_avatar/forum.hdfgroup.org/gheber/32/1919_2.png) [@gheber](https://forum.hdfgroup.org/u/gheber)\
**Post date:** [May 4, 2021, 5:58pm UTC](https://forum.hdfgroup.org/t/how-to-use-h5ocopy-to-copy-a-group-with-hard-links/8443/7 "2021-05-04T17:58:48Z")

</div>

Can you send us the output of `h5dump -pH <your-file.h5>`? G.
