Copying a symbolic link in Python

Just do def copy(src, dst): if os.path.islink(src): linkto = os.readlink(src) os.symlink(linkto, dst) else: shutil.copy(src,dst) shutil.copytree does something similar, but as senderle noted, it’s picky about copying only directories, not single files.

Create symbolic links on server without SSH available?

Use a script. If you have sh, bash or csh available, then you’re nearly as good as if you had an ssh access. If you don’t, then most other scripting languages allow you to create symbolic links on your server. For example, in PHP you would use the symlink() function: symlink(“myOriginalFileOrDirectory”, “mySymbolicLink”); I just had … Read more

How to make a symbolic link with Cygwin in Windows 7

In short, define the following environment variable: CYGWIN=winsymlinks:nativestrict According to Cygwin documentation: If set to winsymlinks:native or winsymlinks:nativestrict, Cygwin creates symlinks as native Windows symlinks on filesystems and OS versions supporting them. The difference between winsymlinks:native and winsymlinks:nativestrict is this: If the filesystem supports native symlinks and Cygwin fails to create a native symlink for … Read more

Find broken symlinks with Python

A common Python saying is that it’s easier to ask forgiveness than permission. While I’m not a fan of this statement in real life, it does apply in a lot of cases. Usually you want to avoid code that chains two system calls on the same file, because you never know what will happen to … Read more

Can I symlink multiple directories into one?

No. You would have to symbolically link all the individual files. What you could do is to create a job to run periodically which basically removed all of the existing symbolic links in images_all, then re-create the links for all files from the three other directories, but it’s a bit of a kludge, something like … Read more