Window7中软连接的使用MkLink

应用场景:
多个项目(或者同一项目不同分支)需要使用同一组依赖文件时,我们希望只在其中一个项目中提供原始文件、而在其它项目中则通过类似linux中的软连接的方式引入。最终既可以减少同一依赖文件库(一个目录中的所有库)的多副本维护(必须保持统一),又可以降低对磁盘空间的占用。
有一个Dependency的文件夹,里面存放了一堆公共库,有三个项目CppDev、CppMain、CppTest中都需要使用该公共库,初始的目录结构大致如下:
D:\CppDev\Dependency
D:\CppMain\Dependency
D:\CppTest\Dependency
由上可知,Dependency保留了三个副本。为了简化,我们使用mkLink来建立软连接
mklink /d D:\CppMain\Dependency D:\CppDev\Dependency
mklink /d D:\CppTest\Dependency D:\CppDev\Dependency

这样CppMain、CppTest中就不再需要维护一个副本了。

最终发现Win7引入了Mklink命令,可以很好地契合这个需求:

MKLINK [[/D] | [/H] | [/J]] Link Target
/D Creates a directory symbolic link. Default is a file symbolic link. /H Creates a hard link instead of a symbolic link. /J Creates a Directory Junction.
/D creates a symbolic link, or a soft link.This essentially acts like a shortcut to a folder in prior versions of Windows, except you don’t have to use an actual shortcut.
/H creates a hard link, which points directly to the file.This option can’t be used for folders directly for some reason, you’ll have to use the next option.
/J creates a “Directory Junction”A Directory Junction is actually just a hard link to a directory. This is a feature that existed prior to Vista as well. If you are trying to symlink to a directory using a hard link, then you should use this option.
Understanding Hard vs Soft Links================================Hard Link
A hard link directly points to the file, and acts to the operating system as if it is the file itself. You’ll want to use this option the majority of the time if you are trying to fake an application’s directory.
Soft Link
A soft link is essentially a shortcut to a file or folder – if you are using Windows explorer, you’ll be redirected to the directory if you double-click on a shortcut, it won’t pretend its part of the filesystem. You can still directly reference or open a file with the symlinked path, and it mostly works.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值