<br><div class="gmail_quote">On Tue, Aug 2, 2011 at 3:13 AM, Thomas Jollans <span dir="ltr"><<a href="mailto:t@jollybox.de">t@jollybox.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div>On 02/08/11 11:32, loial wrote:<br>
> I am trying to hardlink all files in a directory structure using<br>
> os.link.<br>
><br>
> However I do not think it is possible to hard link directories ?<br></div></blockquote><div><br>That is pretty true.  I've heard of hardlinked directories on Solaris, but that's kind of an exception to the general rule.<br>
 <br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div class="im">
> So presumably I would need to do a mkdir for each sub-directory<br>
> encountered?<br>
> Or is there an easier way to hardlink everything in a directory<br>
> structure?.<br>
><br>
> The requirement is for hard links, not symbolic links<br>
><br>
<br>
</div>Yes, you have to mkdir everything. However, there is an easier way:<br>
<br>
subprocess.Popen(['cp','-Rl','target','link'])<br>
<br>
This is assuming that you're only supporting Unices with a working cp<br>
program, but as you're using hard links, that's quite a safe bet, I<br>
should think.<br></blockquote><div><br>A little more portable way:<br><br>$ cd from; find . -print | cpio -pdlv ../to<br>cpio: ./b linked to ../to/./b<br>../to/./b<br>cpio: ./a linked to ../to/./a<br>../to/./a<br>cpio: ./c linked to ../to/./c<br>
../to/./c<br>../to/./d<br>cpio: ./d/1 linked to ../to/./d/1<br>../to/./d/1<br>cpio: ./d/2 linked to ../to/./d/2<br>../to/./d/2<br>cpio: ./d/3 linked to ../to/./d/3<br>../to/./d/3<br>0 blocks<br><br>However, you could do it without a shell command (IOW in pure python) using os.path.walk().<br>
<br></div></div>