本文整理汇总了C#中QuickIOPathInfo类的典型用法代码示例。如果您正苦于以下问题:C# QuickIOPathInfo类的具体用法?C# QuickIOPathInfo怎么用?C# QuickIOPathInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
QuickIOPathInfo类属于命名空间,在下文中一共展示了QuickIOPathInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateDirectory
/// <summary>
/// Creates a new directory. If <paramref name="recursive"/> is false, the parent directory must exists.
/// </summary>
/// <param name="pathInfo"><see cref="QuickIOPathInfo"/></param>
/// <param name="recursive">If <paramref name="recursive"/> is false, the parent directory must exist.</param>
/// <exception cref="PathAlreadyExistsException">The specified path already exists.</exception>
/// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception>
public static void CreateDirectory( QuickIOPathInfo pathInfo, bool recursive = false )
{
if ( recursive )
{
var parent = pathInfo.Parent;
if ( parent.IsRoot )
{
// Root
if ( !parent.Exists )
{
throw new PathNotFoundException( "Root path does not exists. You cannot create a root this way.", parent.FullName );
}
}
else if ( !parent.Exists )
{
CreateDirectory( parent, recursive );
}
}
if ( pathInfo.CheckExistance( QuickIOFileSystemEntryType.Directory ) )
{
return;
}
var created = Win32SafeNativeMethods.CreateDirectory( pathInfo.FullNameUnc, IntPtr.Zero );
var win32Error = Marshal.GetLastWin32Error( );
if ( !created )
{
InternalQuickIOCommon.NativeExceptionMapping( pathInfo.FullName, win32Error );
}
}
示例2: Exists
/// <summary>
/// Checks whether the path with the expected system entry type exists
/// </summary>
/// <param name="pathInfo">A file or a directory</param>
/// <param name="systemEntryType"><see cref="QuickIOFileSystemEntryType"/> you are searching for</param>
/// <returns></returns>
/// <exception cref="UnmatchedFileSystemEntryTypeException">Path exists but it's not the type you're searching for.</exception>
public static Boolean Exists( QuickIOPathInfo pathInfo, QuickIOFileSystemEntryType systemEntryType )
{
switch ( systemEntryType )
{
case QuickIOFileSystemEntryType.Directory:
try
{
InternalQuickIO.LoadDirectoryFromPathInfo( pathInfo );
return true;
}
catch ( PathNotFoundException )
{
return false;
}
case QuickIOFileSystemEntryType.File:
try
{
InternalQuickIO.LoadFileFromPathInfo( pathInfo );
return true;
}
catch ( PathNotFoundException )
{
return false;
}
default:
throw new ArgumentException( "Unknown QuickIOFileSystemEntryType passed." );
}
}
示例3: CreateSafeFileHandle
/// <summary>
/// Returns the <see cref="SafeFileHandle"/> and fills <see cref="Win32FindData"/> from the passes path.
/// </summary>
/// <param name="pathInfo">Path to the file system entry</param>
/// <returns><see cref="SafeFileHandle"/></returns>
/// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception>
internal static SafeFileHandle CreateSafeFileHandle( QuickIOPathInfo pathInfo )
{
Contract.Requires( pathInfo != null );
Contract.Ensures( Contract.Result<SafeFileHandle>() != null );
return CreateSafeFileHandle( pathInfo.FullNameUnc );
}
示例4: AddAttribute
/// <summary>
/// Adds a file attribute
/// </summary>
/// <param name="pathInfo">Affected target</param>
/// <param name="attribute">Attribute to add</param>
/// <returns>true if added. false if already exists in attributes</returns>
public static Boolean AddAttribute( QuickIOPathInfo pathInfo, FileAttributes attribute )
{
if ( ( pathInfo.Attributes & attribute ) != attribute )
{
var attributes = pathInfo.Attributes;
attributes |= attribute;
SetAttributes( pathInfo, attributes );
return true;
}
return false;
}
示例5: Exists
/// <summary>
/// Checks whether the path with the expected system entry type exists
/// </summary>
/// <param name="path">Path to a file or a directory</param>
/// <param name="systemEntryType"><see cref="QuickIOFileSystemEntryType"/> you are searching for</param>
/// <returns></returns>
/// <exception cref="UnmatchedFileSystemEntryTypeException">Path exists but it's not the type you're searching for.</exception>
public static Boolean Exists( String path, QuickIOFileSystemEntryType systemEntryType )
{
var info = new QuickIOPathInfo( path );
if ( !info.Exists )
{
return false;
}
if ( info.IsRoot && systemEntryType == QuickIOFileSystemEntryType.Directory ) // root is always directory
{
return true;
}
if ( info.SystemEntryType == systemEntryType )
{
return true;
}
throw new UnmatchedFileSystemEntryTypeException( systemEntryType, info.SystemEntryType, info.FullName );
}
示例6: QuickIOPathInfoFile
public void QuickIOPathInfoFile()
{
string parent = QuickIOPath.Combine( CurrentPath(), "_TestFiles" );
string fullpath = QuickIOPath.Combine( CurrentPath(), "_TestFiles", "ExistingTestFile.txt" );
string fullPathUnc = QuickIOPath.ToPathUnc( fullpath );
string root = QuickIOPath.GetPathRoot( fullpath );
QuickIOPathInfo pi = new QuickIOPathInfo( fullpath );
pi.Should().NotBe( null );
pi.Name.Should().Be( "ExistingTestFile.txt" );
pi.FullName.Should().Be( fullpath );
pi.FullNameUnc.Should().Be( fullPathUnc );
pi.Parent.Should().Be( parent );
pi.Root.Should().Be( root );
pi.IsRoot.Should().Be( false );
pi.FindData.Should().NotBe( null );
InternalHelpers.ContainsFileAttribute( pi.Attributes, FileAttributes.Directory ).Should().Be( false );
pi.Exists.Should().Be( true );
pi.SystemEntryType.Should().Be( QuickIOFileSystemEntryType.File );
}
示例7: EnumerateFileSystemEntryPaths
/// <summary>
/// Determined all sub file system entries of a directory
/// </summary>
/// <param name="pathInfo">Path of the directory</param>
/// <param name="pattern">Search pattern. Uses Win32 native filtering.</param>
/// <param name="searchOption"><see cref="SearchOption"/></param>
/// <param name="pathFormatReturn">Specifies the type of path to return.</param>
/// <param name="enumerateOptions">The enumeration options for exception handling</param>
/// <returns>Collection of <see cref="QuickIODirectoryInfo"/></returns>
/// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception>
internal static IEnumerable<KeyValuePair<String, QuickIOFileSystemEntryType>> EnumerateFileSystemEntryPaths( QuickIOPathInfo pathInfo, String pattern = QuickIOPatternConstants.All, SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None, QuickIOPathType pathFormatReturn = QuickIOPathType.Regular )
{
return EnumerateFileSystemEntryPaths( pathInfo.FullNameUnc, pattern, searchOption, enumerateOptions, pathFormatReturn );
}
示例8: EnumerateDirectoryMetadata
/// <summary>
/// Determined metadata of directory
/// </summary>
/// <param name="pathInfo">Path of the directory</param>
/// <param name="enumerateOptions">The enumeration options for exception handling</param>
/// <returns><see cref="QuickIODirectoryMetadata"/> started with the given directory</returns>
/// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception>
internal static QuickIODirectoryMetadata EnumerateDirectoryMetadata( QuickIOPathInfo pathInfo, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None )
{
return EnumerateDirectoryMetadata( pathInfo.FullNameUnc, pathInfo.FindData, enumerateOptions );
}
示例9: CreateSafeFileHandle
/// <summary>
/// Returns the <see cref="SafeFileHandle"/> and fills <see cref="Win32FindData"/> from the passes path.
/// </summary>
/// <param name="info">Path to the file system entry</param>
/// <returns><see cref="SafeFileHandle"/></returns>
/// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception>
internal static SafeFileHandle CreateSafeFileHandle( QuickIOPathInfo info )
{
return CreateSafeFileHandle( info.FullNameUnc );
}
示例10: SetLastWriteTimeUtc
/// <summary>
/// Sets the time at which the file or directory was last written to (UTC)
/// </summary>
/// <param name="pathInfo">Affected file or directory</param>
/// <param name="utcTime">The time that is to be used (UTC)</param>
public static void SetLastWriteTimeUtc( QuickIOPathInfo pathInfo, DateTime utcTime )
{
var longTime = utcTime.ToFileTime( );
using ( var fileHandle = OpenReadWriteFileSystemEntryHandle( pathInfo.FullNameUnc ) )
{
if ( !Win32SafeNativeMethods.SetLastWriteFileTime( fileHandle, IntPtr.Zero, IntPtr.Zero, ref longTime ) )
{
var win32Error = Marshal.GetLastWin32Error( );
InternalQuickIOCommon.NativeExceptionMapping( pathInfo.FullName, win32Error );
}
}
}
示例11: SetAllFileTimes
/// <summary>
/// Sets the dates and times of given directory or file.
/// </summary>
/// <param name="pathInfo">Affected file or directory</param>
/// <param name="creationTimeUtc">The time that is to be used (UTC)</param>
/// <param name="lastAccessTimeUtc">The time that is to be used (UTC)</param>
/// <param name="lastWriteTimeUtc">The time that is to be used (UTC)</param>
public static void SetAllFileTimes( QuickIOPathInfo pathInfo, DateTime creationTimeUtc, DateTime lastAccessTimeUtc, DateTime lastWriteTimeUtc )
{
var longCreateTime = creationTimeUtc.ToFileTime( );
var longAccessTime = lastAccessTimeUtc.ToFileTime( );
var longWriteTime = lastWriteTimeUtc.ToFileTime( );
using ( var fileHandle = OpenReadWriteFileSystemEntryHandle( pathInfo.FullNameUnc ) )
{
if ( Win32SafeNativeMethods.SetAllFileTimes( fileHandle, ref longCreateTime, ref longAccessTime, ref longWriteTime ) == 0 )
{
var win32Error = Marshal.GetLastWin32Error( );
InternalQuickIOCommon.NativeExceptionMapping( pathInfo.FullName, win32Error );
}
}
}
示例12: EnumerateFileSystemEntryPaths
/// <summary>
/// Determined all sub file system entries of a directory
/// </summary>
/// <param name="pathInfo">Path of the directory</param>
/// <param name="searchOption"><see cref="SearchOption"/></param>
/// <param name="pathFormatReturn">Specifies the type of path to return.</param>
/// <param name="enumerateOptions">The enumeration options for exception handling</param>
/// <returns>Collection of <see cref="QuickIODirectoryInfo"/></returns>
/// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception>
internal static IEnumerable<KeyValuePair<String, QuickIOFileSystemEntryType>> EnumerateFileSystemEntryPaths( QuickIOPathInfo pathInfo, SearchOption searchOption, QuickIOEnumerateOptions enumerateOptions, QuickIOPathType pathFormatReturn = QuickIOPathType.Regular )
{
return EnumerateFileSystemEntryPaths( pathInfo.FullNameUnc, searchOption, enumerateOptions, pathFormatReturn );
}
示例13: EnumerateFileSystemEntries
/// <summary>
/// Determined all sub system entries of a directory
/// </summary>
/// <param name="pathInfo">Path of the directory</param>
/// <param name="searchOption"><see cref="SearchOption"/></param>
/// <param name="enumerateOptions">The enumeration options for exception handling</param>
/// <returns>Collection of <see cref="QuickIODirectoryInfo"/></returns>
/// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception>
internal static IEnumerable<KeyValuePair<QuickIOPathInfo, QuickIOFileSystemEntryType>> EnumerateFileSystemEntries( QuickIOPathInfo pathInfo, SearchOption searchOption, QuickIOEnumerateOptions enumerateOptions )
{
return EnumerateFileSystemEntries( pathInfo.FullNameUnc, searchOption, enumerateOptions );
}
示例14: EnumerateFiles
/// <summary>
/// Determined all files of a directory
/// </summary>
/// <param name="pathInfo">Path of the directory</param>
/// <param name="searchOption"><see cref="SearchOption"/></param>
/// <returns>Collection of files</returns>
/// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception>
internal static IEnumerable<QuickIOFileInfo> EnumerateFiles( QuickIOPathInfo pathInfo, SearchOption searchOption, QuickIOEnumerateOptions enumerateOptions )
{
return EnumerateFiles( pathInfo.FullNameUnc, searchOption, enumerateOptions );
}
示例15: Exists
/// <summary>
/// Reurns true if passed path exists
/// </summary>
/// <param name="pathInfo">Path to check</param>
public static Boolean Exists( QuickIOPathInfo pathInfo )
{
var win32FindData = new Win32FindData( );
int win32Error;
var path = pathInfo.FullNameUnc;
if ( pathInfo.IsRoot )
{
path = QuickIOPath.Combine( path, "*" );
}
using ( var fileHandle = FindFirstSafeFileHandle( path, win32FindData, out win32Error ) )
{
// Take care of invalid handles
return !fileHandle.IsInvalid;
}
}