Hardlink sub-directories and files
__peter__ at web.de
Tue Aug 2 12:01:19 CEST 2011
> I am trying to hardlink all files in a directory structure using
> This works fine for files, but the directory also contains sub-
> directories (which themselves contain files and sub-directories).
> However I do not think it is possible to hard link directories ?
> So presumably I would need to do a mkdir for each sub-directory
> Or is there an easier way to hardlink everything in a directory
> The requirement is for hard links, not symbolic links
You cannot make hardlinks for directories, that's a restriction imposed by
the operating system.
Look for shutil.copytree() for a template of what you are trying to do; you
might even monkepatch it
copy2 = shutil.copy2
shutil.copy2 = os.link
shutil.copy2 = copy2
if you are OK with a quick-and-dirty solution.
More information about the Python-list