0

我有一段代码,比如 if

        // 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 即使lastPathSegment它确实是一个目录。知道如何准确区分吗?

4

1 回答 1

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; 
     }
 }

于 2018-07-20T17:51:15.867 回答