本文整理汇总了C#中System.IO.FileSystemInfo.IsFile方法的典型用法代码示例。如果您正苦于以下问题:C# FileSystemInfo.IsFile方法的具体用法?C# FileSystemInfo.IsFile怎么用?C# FileSystemInfo.IsFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.FileSystemInfo
的用法示例。
在下文中一共展示了FileSystemInfo.IsFile方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: recursiveDelete
/// <summary>
/// Utility method to delete a directory recursively. It is
/// also used internally. If a file or directory cannot be removed
/// it throws an AssertionFailure.
/// </summary>
/// <param name="fs"></param>
/// <param name="silent"></param>
/// <param name="name"></param>
/// <param name="failOnError"></param>
/// <returns></returns>
protected static bool recursiveDelete(FileSystemInfo fs, bool silent, string name, bool failOnError)
{
Debug.Assert(!(silent && failOnError));
if (fs.IsFile())
{
fs.DeleteFile();
return silent;
}
var dir = new DirectoryInfo(fs.FullName);
if (!dir.Exists) return silent;
try
{
FileSystemInfo[] ls = dir.GetFileSystemInfos();
foreach (FileSystemInfo e in ls)
{
silent = recursiveDelete(e, silent, name, failOnError);
}
dir.Delete();
}
catch (IOException e)
{
//ReportDeleteFailure(name, failOnError, fs);
Console.WriteLine(name + ": " + e.Message);
}
return silent;
}
示例2: recursiveDelete
private static bool recursiveDelete(string testName, FileSystemInfo fs, bool silent, bool failOnError)
{
Debug.Assert(!(silent && failOnError));
if (fs.IsFile())
{
fs.DeleteFile();
return silent;
}
var dir = new DirectoryInfo(fs.FullName);
if (!dir.Exists) return silent;
try
{
FileSystemInfo[] ls = dir.GetFileSystemInfos();
foreach (FileSystemInfo e in ls)
{
silent = recursiveDelete(testName, e, silent, failOnError);
}
dir.Delete();
}
catch (IOException e)
{
ReportDeleteFailure(testName, failOnError, fs, e.Message);
}
return silent;
}
示例3: FileEntry
public FileEntry(FileSystemInfo f)
{
_file = f;
_fileLength = -1;
if (_file.IsDirectory())
{
_mode = PathUtil.CombineDirectoryPath((DirectoryInfo)_file, Constants.DOT_GIT).Exists ? FileMode.GitLink : FileMode.Tree;
}
else if (_file.IsFile())
{
_mode = FS.canExecute(_file) ? FileMode.ExecutableFile : FileMode.RegularFile;
}
}
示例4: recursiveDelete
private static void recursiveDelete(string testName, FileSystemInfo fs, bool failOnError)
{
if (fs.IsFile())
{
if (!fs.DeleteFile())
{
throw new IOException("Unable to delete file: " + fs.FullName);
}
// Deleting a file only marks it for deletion, following code blocks until
// the file is actually deleted. For a more thorough explanation see the
// comment below @ the directory.Delete()
while (File.Exists(fs.FullName))
{
Thread.Sleep(0);
}
return;
}
var dir = new DirectoryInfo(fs.FullName);
if (!Directory.Exists(dir.FullName)) return;
try
{
FileSystemInfo[] ls = dir.GetFileSystemInfos();
foreach (FileSystemInfo e in ls)
{
recursiveDelete(testName, e, failOnError);
}
dir.Delete();
// dir.Delete() only marks the directory for deletion (see also: http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/a2fcc569-1835-471f-b731-3fe9c6bcd2d9),
// so it creates a race condition between the actual deletion of this directory, and the
// deletion of the parent directory. If this directory is not deleted when the parent directory
// is tried to be deleted, an IOException ("Directory not empty") will be thrown.
// The following code blocks untill the directory is actually deleted.
// (btw, dir.Exists keeps returning true on my (Windows 7) machine, even if the Explorer and Command
// say otherwise)
while (Directory.Exists(dir.FullName))
{
Thread.Sleep(0);
}
}
catch (IOException ex)
{
ReportDeleteFailure(testName, failOnError, fs, ex.ToString());
}
}
示例5: CorrectFilePath
private static string CorrectFilePath(string parts, FileSystemInfo source)
{
if (string.IsNullOrEmpty(parts))
return source.FullName;
if (parts.Trim() == "." && (!source.IsFile()))
return Path.Combine(((DirectoryInfo)source).Parent.FullName, "Output");
var outputPath = source.FullName;
foreach (var part in parts.Split('/'))
{
outputPath = Path.Combine(outputPath, part);
}
return outputPath;
}