added methods for symlink creation
This commit is contained in:
parent
9b41e2230c
commit
861346456c
@ -136,10 +136,24 @@ namespace DTLib.Filesystem
|
|||||||
dirInfo.SetAccessControl(dirSecurity);
|
dirInfo.SetAccessControl(dirSecurity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void CreateSymlink(string symlinkName, string sourceName)
|
public static void CreateSymlink(string sourceName, string symlinkName)
|
||||||
{
|
{
|
||||||
|
if (symlinkName.Contains("\\"))
|
||||||
|
Directory.Create(symlinkName.Remove(symlinkName.LastIndexOf('\\')));
|
||||||
if (!Symlink.CreateSymbolicLink(symlinkName, sourceName, Symlink.SymlinkTarget.Directory))
|
if (!Symlink.CreateSymbolicLink(symlinkName, sourceName, Symlink.SymlinkTarget.Directory))
|
||||||
throw new InvalidOperationException($"some error occured while creating symlink\nCreateSymlink({symlinkName}, {sourceName})");
|
throw new InvalidOperationException($"some error occured while creating symlink\nDirectory.CreateSymlink({symlinkName}, {sourceName})");
|
||||||
|
}
|
||||||
|
|
||||||
|
// copies directory with symlinks instead of files
|
||||||
|
public static int SymCopy(string srcdir, string newdir)
|
||||||
|
{
|
||||||
|
var files = Directory.GetAllFiles(srcdir);
|
||||||
|
if (!srcdir.EndsWith('\\')) srcdir += '\\';
|
||||||
|
if (!newdir.EndsWith('\\')) newdir += '\\';
|
||||||
|
int i = 0;
|
||||||
|
for (; i < files.Count; i++)
|
||||||
|
File.CreateSymlink(files[i], files[i].Replace(srcdir, newdir));
|
||||||
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -75,10 +75,12 @@ namespace DTLib.Filesystem
|
|||||||
return System.IO.File.Open(file, System.IO.FileMode.Append);
|
return System.IO.File.Open(file, System.IO.FileMode.Append);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void CreateSymlink(string symlinkName, string sourceName)
|
public static void CreateSymlink(string sourceName, string symlinkName)
|
||||||
{
|
{
|
||||||
|
if (symlinkName.Contains("\\"))
|
||||||
|
Directory.Create(symlinkName.Remove(symlinkName.LastIndexOf('\\')));
|
||||||
if (!Symlink.CreateSymbolicLink(symlinkName, sourceName, Symlink.SymlinkTarget.File))
|
if (!Symlink.CreateSymbolicLink(symlinkName, sourceName, Symlink.SymlinkTarget.File))
|
||||||
throw new InvalidOperationException($"some error occured while creating symlink\nCreateSymlink({symlinkName}, {sourceName})");
|
throw new InvalidOperationException($"some error occured while creating symlink\nFile.CreateSymlink({symlinkName}, {sourceName})");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user