程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> 循環獲取文件夾下的文件列表

循環獲取文件夾下的文件列表

編輯:C#入門知識

private void GetFileList(string strCurDir)
        {
            string FileName, FileExt;

            ///文件大小
            long FileSize;

            ///最後修改時間;
            DateTime FileModify;


            ///初始化時,默認為當前頁面所在的目錄
            strCurDir = Server.MapPath(strCurDir);
            // lblCurDir.Text = strCurDir;
            // /txtCurDir.Text = strCurDir;
            if (Directory.Exists(Path.GetDirectoryName(strCurDir)))
            {
                //Directory.CreateDirectory(Path.GetDirectoryName(filePath));




                FileInfo fi;
                DirectoryInfo dir;
                TableCell td;
                TableRow tr;
                tr = new TableRow();

                ///動態添加單元格內容
                td = new TableCell();
                td.Controls.Add(new LiteralControl("文件名"));
                tr.Cells.Add(td);
                td = new TableCell();
                td.Controls.Add(new LiteralControl("文件類型"));
                tr.Cells.Add(td);
                td = new TableCell();
                td.Controls.Add(new LiteralControl("文件大小"));
                tr.Cells.Add(td);
                td = new TableCell();
                td.Controls.Add(new LiteralControl("最後修改時間"));
                tr.Cells.Add(td);

                tableDirInfo.Rows.Add(tr);

                ///針對當前目錄建立目錄引用對象
                DirectoryInfo dirInfo = new DirectoryInfo(strCurDir);

                ///循環判斷當前目錄下的文件和目錄
                foreach (FileSystemInfo fsi in dirInfo.GetFileSystemInfos())
                {
                    FileName = "";
                    FileExt = "";
                    FileSize = 0;

                    ///如果是文件
                    if (fsi is FileInfo)
                    {
                        fi = (FileInfo)fsi;

                        ///取得文件名
                        FileName = fi.Name;

                        ///取得文件的擴展名
                        FileExt = fi.Extension;

                        ///取得文件的大小
                        FileSize = fi.Length;

                        ///取得文件的最後修改時間
                        FileModify = fi.LastWriteTime;

                        //string files = fid.Text + "/" + id.Text + "/" + FileName;
                        //string thunb = "thumb/" + FileName;
                        //string opath = Server.MapPath("upfile/" + dir.Name + "/" + FileName);
                        //string tpath = Server.MapPath("upfile/thumb/" + FileName);
                        //ThumbImage.MakeThumbnail(opath, tpath, 142, 100, "D&qu

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved