什么是C#相当于&QUOT的; MKLINK / J"? [英] What the C# equivalent of "mklink /J"?
本文介绍了什么是C#相当于&QUOT的; MKLINK / J"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道如何在一个.BAT脚本在Windows中创建符号链接:
I know how to create a symbolic link in windows in a .bat script:
mklink /J <LinkPath> <OriginalResourcePath>
如何做同样的事情在C#?
How to do the same thing in C# ?
我没有高兴的google搜索,因为我在C#初学者,我可能不使用正确的术语。任何人都可以指示使用的API吗?
I've not been happy with the googling, because i'm a beginner in C# and I probably don't use the right terms. Anybody can indicate the API to use please ?
推荐答案
下面是一个code例如:
Here's a code example:
namespace ConsoleApplication
{
class Program
{
[DllImport("kernel32.dll")]
static extern bool CreateSymbolicLink(
string lpSymlinkFileName, string lpTargetFileName, SymbolicLink dwFlags);
enum SymbolicLink
{
File = 0,
Directory = 1
}
static void Main(string[] args)
{
string symbolicLink = @"c:\bar.txt";
string fileName = @"c:\temp\foo.txt";
using (var writer = File.CreateText(fileName))
{
writer.WriteLine("Hello World");
}
CreateSymbolicLink(symbolicLink, fileName, SymbolicLink.File);
}
}
}
这将创建一个名为在C跳回到bar.txt一个符号链接文件:-drive可链接到存储在C foo.txt的文本文件:\\ temp目录
This will create a symbolic link file called bar.txt on the C:-drive which links to the foo.txt text file stored in the C:\temp directory.
这篇关于什么是C#相当于&QUOT的; MKLINK / J&QUOT;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文