本文整理汇总了C#中IDirectory.Create方法的典型用法代码示例。如果您正苦于以下问题:C# IDirectory.Create方法的具体用法?C# IDirectory.Create怎么用?C# IDirectory.Create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDirectory
的用法示例。
在下文中一共展示了IDirectory.Create方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CopyTo
/// <summary>
/// Copy "this" directory (<paramref name="a_this"/>) to the given destination directory (<paramref name="a_destination"/>).
/// </summary>
/// <param name="a_this">"This" directory.</param>
/// <param name="a_destination">Destination directory.</param>
/// <exception cref="NullReferenceException">Thrown if <paramref name="a_this"/> is null.</exception>
/// <exception cref="ArgumentNullException">Thrown if <paramref name="a_destination"/> is null.</exception>
public static void CopyTo(this IDirectory a_this, IDirectory a_destination)
{
#region Argument Validation
if (a_this == null)
throw new NullReferenceException(nameof(a_this));
if (a_destination == null)
throw new ArgumentNullException(nameof(a_destination));
#endregion
a_destination.Create();
foreach (var file in a_this.Files())
{
var dest = a_destination.File(file.Name);
file.CopyTo(dest);
}
foreach (var directory in a_this.Directories())
{
var dest = a_destination.Directory(directory.Name);
directory.CopyTo(dest);
}
}
示例2: ServiceModelCodeGenerator
protected ServiceModelCodeGenerator(IDirectory directory, CodeGenerationOptions options)
{
this.Options = options;
this.directory = directory;
directory.Create(true);
}
示例3: Create
/// <summary>
/// Creates a junction point from the specified directory to the specified target directory.
/// </summary>
/// <remarks>
/// Only works on NTFS.
/// </remarks>
/// <param name = "junctionPoint">The junction point path</param>
/// <param name = "targetDir">The target directory</param>
/// <param name = "overwrite">If true overwrites an existing reparse point or empty directory</param>
/// <exception cref = "IOException">Thrown when the junction point could not be created or when
/// an existing directory was found and <paramref name = "overwrite" /> if false</exception>
public static void Create(IDirectory junctionPoint, string targetDir, bool overwrite)
{
//targetDir = Path.GetFullPath(targetDir);
if (!Directory.Exists(targetDir))
throw new IOException("Target path does not exist or is not a directory.");
if (junctionPoint.Exists)
{
if (!overwrite)
throw new IOException("Directory already exists and overwrite parameter is false.");
}
else
junctionPoint.Create();
using (var handle = OpenReparsePoint(junctionPoint.Path.FullPath, EFileAccess.GenericWrite))
{
var targetDirBytes = Encoding.Unicode.GetBytes(NonInterpretedPathPrefix + Path.GetFullPath(targetDir));
var reparseDataBuffer = new REPARSE_DATA_BUFFER();
reparseDataBuffer.ReparseTag = IO_REPARSE_TAG_MOUNT_POINT;
reparseDataBuffer.ReparseDataLength = (ushort) (targetDirBytes.Length + 12);
reparseDataBuffer.SubstituteNameOffset = 0;
reparseDataBuffer.SubstituteNameLength = (ushort) targetDirBytes.Length;
reparseDataBuffer.PrintNameOffset = (ushort) (targetDirBytes.Length + 2);
reparseDataBuffer.PrintNameLength = 0;
reparseDataBuffer.PathBuffer = new byte[0x3ff0];
Array.Copy(targetDirBytes, reparseDataBuffer.PathBuffer, targetDirBytes.Length);
var inBufferSize = Marshal.SizeOf(reparseDataBuffer);
var inBuffer = Marshal.AllocHGlobal(inBufferSize);
try
{
Marshal.StructureToPtr(reparseDataBuffer, inBuffer, false);
int bytesReturned;
var result = DeviceIoControl(handle.DangerousGetHandle(), FSCTL_SET_REPARSE_POINT,
inBuffer, targetDirBytes.Length + 20, IntPtr.Zero, 0, out bytesReturned, IntPtr.Zero);
if (!result)
ThrowLastWin32Error("Unable to create junction point.");
}
finally
{
Marshal.FreeHGlobal(inBuffer);
}
}
}
示例4: TemporaryDirectory
public TemporaryDirectory(IDirectory unerlyingDirectory)
{
UnderlyingDirectory = unerlyingDirectory;
if (!UnderlyingDirectory.Exists)
UnderlyingDirectory.Create();
}
示例5: DirectoryMigrationsLibrary
public DirectoryMigrationsLibrary(IDirectory getDirectoryInfo = null)
{
_getDirectoryInfo = getDirectoryInfo;
if (_getDirectoryInfo != null) _getDirectoryInfo.Create();
}