本文整理汇总了C#中IFileInfo.IsDirectory方法的典型用法代码示例。如果您正苦于以下问题:C# IFileInfo.IsDirectory方法的具体用法?C# IFileInfo.IsDirectory怎么用?C# IFileInfo.IsDirectory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFileInfo
的用法示例。
在下文中一共展示了IFileInfo.IsDirectory方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateEntry
protected string GenerateEntry(IFileInfo info)
{
StringBuilder entry = new StringBuilder();
bool isDirectory = info.IsDirectory();
if (isDirectory)
{
entry.Append("Type=dir; ");
string dirName = FileNameHelpers.GetDirectoryName(info.Path());
entry.Append(dirName);
}
else
{
entry.Append(string.Format("Type=file;Size={0};Modify={1}; ", info.GetSize(), info.GetModifiedTime().ToString("yyyyMMddHHmmss")));
entry.Append(FileNameHelpers.GetFileName(info.Path()));
}
return entry.ToString();
}
示例2: GetLongProperty
private string GetLongProperty(IFileInfo info)
{
if (info == null)
return null;
var stringBuilder = new StringBuilder();
// permissions
string sAttributes = info.GetAttributeString();
stringBuilder.Append(sAttributes);
stringBuilder.Append(" 1 owner group");
// check whether info is directory
bool isDirectory = info.IsDirectory();
// size
string sFileSize = info.GetSize().ToString(); // if info is directory, the size will be 1
stringBuilder.Append(TextHelpers.RightAlignString(sFileSize, 13, ' '));
stringBuilder.Append(" ");
// modify time
DateTimeOffset fileDate = info.GetModifiedTime(); //if info is directory, the modify time will be the current time
// month
stringBuilder.Append(TextHelpers.Month(fileDate.Month));
stringBuilder.Append(" ");
// day
string sDay = fileDate.Day.ToString();
if (sDay.Length == 1)
stringBuilder.Append(" ");
stringBuilder.Append(sDay);
stringBuilder.Append(" ");
// year or hour:min
if (fileDate.Year < DateTime.Now.Year)
{
stringBuilder.Append(" " + fileDate.Year);
}
else
{
stringBuilder.Append(string.Format("{0:hh}:{1:mm}", fileDate, fileDate));
}
stringBuilder.Append(" ");
// filename
string path = info.Path();
if (isDirectory)
stringBuilder.Append(FileNameHelpers.GetDirectoryName(path));
else
stringBuilder.Append(FileNameHelpers.GetFileName(path));
// end
stringBuilder.Append("\r\n");
return stringBuilder.ToString();
}