zoukankan      html  css  js  c++  java
  • 递归遍历指定目录,获取该目录下最大的文件信息

    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Net;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                FileInfo maxFile = GetMaxFileInfo(new DirectoryInfo(@"e:
    oot"), null);
                if (maxFile != null)
                {
                    using (FileStream fsRead = new FileStream(maxFile.FullName, FileMode.Open))
                    {
                        long fsLen = fsRead.Length;
                        byte[] heByte = new byte[fsLen];
                        int r = fsRead.Read(heByte, 0, heByte.Length);
                        string myStr = Encoding.Default.GetString(heByte);
                        Console.WriteLine(myStr);
                    }
                }
                Console.Read();
            }
    
            public static FileInfo GetMaxFileInfo(FileSystemInfo info, FileInfo maxFile)
            {
                if (info.Exists == false) return null;
                DirectoryInfo dir = info as DirectoryInfo;
                if (dir == null) return null;
                FileSystemInfo[] files = dir.GetFileSystemInfos();
                for (int i = 0; i < files.Length; i++)
                {
                    FileInfo file = files[i] as FileInfo;
                    if (file == null)
                    {
                        maxFile = GetMaxFileInfo(files[i], maxFile);
                    }
                    else
                    {
                        if (maxFile == null)
                        {
                            maxFile = file;
                        }
                        else if (maxFile.Length < file.Length)
                        {
                            maxFile = file;
                        }
                    }
                }
                return maxFile;
            }
        }
    }
  • 相关阅读:
    最短路径问题
    这是我的第一篇博客
    Time Series Anomaly Detection
    R-CNN, Fast R-CNN, Faster R-CNN, Mask R-CNN
    database 学习
    AWS Cloud Practioner 官方课程笔记
    Cassandra commands
    go 语言学习
    [Udemy] ES 7 and Elastic Stack
    第9章 内联函数
  • 原文地址:https://www.cnblogs.com/tqlin/p/5177725.html
Copyright © 2011-2022 走看看