我有一段类似if的代码
$thumbnailPath
我发现的是错误的,因为即使 // last path segement can be like "binaries.x86" since
// directories can have `.` characters in them
if ((lastItemInPath = cloudFileDirectory.GetFileReference(lastPathSegment)) != null)
{
// the last path segment is a file
return lastItemInPath;
}
else if ((lastItemInPath = cloudFileDirectory.GetDirectoryReference(lastPathSegment)) != null)
{
// the last path segment is a directory
return lastItemInPath;
}
确实是目录,第一个if
仍返回true。知道我该如何准确区分吗?
答案 0 :(得分:0)
Try this
CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("Azure Storage Connection String"));
CloudFileClient fileClient = cloudStorageAccount.CreateCloudFileClient();
CloudFileShare fileShare = fileClient.GetShareReference("File Share Name");
IEnumerable<IListFileItem> fileList = fileShare.GetRootDirectoryReference().ListFilesAndDirectories();
foreach (var fileTemp in fileList)
{
switch (fileTemp.GetType().Name)
{
case "CloudFile":
//Write your logic here
break;
case "CloudFileDirectory":
//Write your logic here
break;
}
}