0

I got this as my main directory.

└───etc_core
    └───modules_core
        ├───core_module_1
        ├───core_module_2
        └───core_module_3

I got another directory with the same structure, but with different modules.

└───etc_custom
    └───modules_custom
        ├───custom_module_1
        ├───custom_module_2
        └───custom_module_3

Desired structure

└───etc_core
    └───modules_core
        ├───core_module_1
        ├───core_module_2
        ├───core_module_3
        ├───custom_module_1 (link to etc_custom/modules_custom/custom_module_1/)
        ├───custom_module_2 (link to etc_custom/modules_custom/custom_module_2/)
        └───custom_module_3 (link to etc_custom/modules_custom/custom_module_3/)

Without symlinking each module, is there any easy way to mount etc_custom/modules_custom onto etc_core/modules_core recursively?

Ravenous
  • 1,112
  • 11
  • 25
  • No, you have to call `CreateSymbolicLinkW` for each directory with the flag `SYMBOLIC_LINK_FLAG_DIRECTORY`. The target doesn't have to exist. First try with the extra flag `SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE` to support unprivileged users in Windows 10 developer mode. If it fails as an invalid parameter, try again without that flag, but the effective user will need SeCreateSymbolicLinkPrivilege. – Eryk Sun Mar 17 '19 at 02:32
  • Note that, despite the documentation, the user doesn't have to be elevated to have SeCreateSymbolicLinkPrivilege. Elevation is only required if the privilege comes from the Administrators group, but it can be assigned to other groups by local policy, such as "Authenticated Users". – Eryk Sun Mar 17 '19 at 02:33
  • 1
    Since the targets are directories you could also use a junction (i.e. a mountpoint, like a Unix bind mount). Creating a junction is unprivileged, but there's no simple API. It requires creating the directory and calling `DeviceIoControl` with `FSCTL_SET_REPARSE_POINT` and a `REPARSE_DATA_BUFFER` using the `MountPointReparseBuffer` field and the reparse tag `IO_REPARSE_TAG_MOUNT_POINT`. – Eryk Sun Mar 17 '19 at 02:40
  • Thanks a lot. I'll see what I can do, it's a one-time thing that I need in order to adapt a bunch of stuff, and the number of directories is under 30 and can be done by hand, I was just lazy to do it by hand or write a shell script for it, hoping there is a more straightforward way of doing it. – Ravenous Mar 17 '19 at 12:50
  • You didn't specify a language. CMD's `mklink` command creates symbolic links and junctions. Use `/d` to create a directory symbolic link and `/j` to create a junction. The target directory need not exist. – Eryk Sun Mar 17 '19 at 13:50
  • Got it, thanks. This is more related to the OS, not the language, I could do it in any language or using CMD's `mklink` or Power Shell's `New-Item -Path Y -ItemType SymbolicLink -Value X` – Ravenous Mar 17 '19 at 13:57
  • 1
    I'm not sure about PowerShell with symlinks to non-existing directories. Notice that they only have a `SymbolicLink` type. There's no `SymbolicLinkD` type for a directory symbolic link. It determines the real type based on the target if it exists. Otherwise, if the target doesn't exist, it creates a regular file symlink. – Eryk Sun Mar 17 '19 at 14:02

0 Answers0