• 大小: 39KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-27
  • 语言: C#
  • 标签:

资源简介

1、判断问价夹是不是存在 2、添加删除赋值文件夹 3、移动文件夹 4、遍历文件夹

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace GetDirectoryInfo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender EventArgs e)
        {
            listView1.Items.Clear();
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox1.Text = folderBrowserDialog1.SelectedPath;
                //实例化DirectoryInfo对象
                DirectoryInfo dinfo = new DirectoryInfo(textBox1.Text);
                //获取指定目录下的所有子目录及文件类型
                FileSystemInfo[] fsinfos = dinfo.GetFileSystemInfos();
                foreach (FileSystemInfo fsinfo in fsinfos)
                {
                    if (fsinfo is DirectoryInfo)    //判断是否文件夹
                    {
                        //使用获取的文件夹名称实例化DirectoryInfo对象
                        DirectoryInfo dirinfo = new DirectoryInfo(fsinfo.FullName);
                        //为ListView控件添加文件夹信息
                        listView1.Items.Add(dirinfo.Name);
                        listView1.Items[listView1.Items.Count - 1].SubItems.Add(dirinfo.FullName);
                        listView1.Items[listView1.Items.Count - 1].SubItems.Add(““);
                        listView1.Items[listView1.Items.Count - 1].SubItems.Add(dirinfo.CreationTime.ToShortDateString());
                    }
                    else
                    {
                        //使用获取的文件名称实例化FileInfo对象
                        FileInfo finfo = new FileInfo(fsinfo.FullName);
                        //为ListView控件添加文件信息
                        listView1.Items.Add(finfo.Name);
                        listView1.Items[listView1.Items.Count - 1].SubItems.Add(finfo.FullName);
                        listView1.Items[listView1.Items.Count - 1].SubItems.Add(finfo.Length.ToString());
                        listView1.Items[listView1.Items.Count - 1].SubItems.Add(finfo.CreationTime.ToShortDateString());
                    }
                }
            }
        }
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      10240  2009-04-11 14:09  例19.24\GetDirectoryInfo\GetDirectoryInfo\bin\Debug\GetDirectoryInfo.exe

     文件      22016  2009-04-11 14:09  例19.24\GetDirectoryInfo\GetDirectoryInfo\bin\Debug\GetDirectoryInfo.pdb

     文件      14328  2009-04-11 14:10  例19.24\GetDirectoryInfo\GetDirectoryInfo\bin\Debug\GetDirectoryInfo.vshost.exe

     文件       2443  2009-04-11 14:09  例19.24\GetDirectoryInfo\GetDirectoryInfo\Form1.cs

     文件       5198  2009-04-11 14:09  例19.24\GetDirectoryInfo\GetDirectoryInfo\Form1.designer.cs

     文件       6022  2009-04-11 14:09  例19.24\GetDirectoryInfo\GetDirectoryInfo\Form1.resx

     文件       3778  2009-04-11 14:09  例19.24\GetDirectoryInfo\GetDirectoryInfo\GetDirectoryInfo.csproj

     文件        971  2009-04-11 14:10  例19.24\GetDirectoryInfo\GetDirectoryInfo\obj\Debug\GetDirectoryInfo.csproj.FileListAbsolute.txt

     文件        847  2009-04-11 14:09  例19.24\GetDirectoryInfo\GetDirectoryInfo\obj\Debug\GetDirectoryInfo.csproj.GenerateResource.Cache

     文件      10240  2009-04-11 14:09  例19.24\GetDirectoryInfo\GetDirectoryInfo\obj\Debug\GetDirectoryInfo.exe

     文件        180  2009-04-11 14:09  例19.24\GetDirectoryInfo\GetDirectoryInfo\obj\Debug\GetDirectoryInfo.Form1.resources

     文件      22016  2009-04-11 14:09  例19.24\GetDirectoryInfo\GetDirectoryInfo\obj\Debug\GetDirectoryInfo.pdb

     文件        180  2009-04-11 14:09  例19.24\GetDirectoryInfo\GetDirectoryInfo\obj\Debug\GetDirectoryInfo.Properties.Resources.resources

     文件        497  2009-04-11 14:08  例19.24\GetDirectoryInfo\GetDirectoryInfo\Program.cs

     文件       1388  2009-04-11 14:08  例19.24\GetDirectoryInfo\GetDirectoryInfo\Properties\AssemblyInfo.cs

     文件       2882  2009-04-11 14:08  例19.24\GetDirectoryInfo\GetDirectoryInfo\Properties\Resources.Designer.cs

     文件       5612  2009-04-11 14:08  例19.24\GetDirectoryInfo\GetDirectoryInfo\Properties\Resources.resx

     文件       1101  2009-04-11 14:08  例19.24\GetDirectoryInfo\GetDirectoryInfo\Properties\Settings.Designer.cs

     文件        249  2009-04-11 14:08  例19.24\GetDirectoryInfo\GetDirectoryInfo\Properties\Settings.settings

     文件        938  2009-04-11 14:08  例19.24\GetDirectoryInfo\GetDirectoryInfo.sln

    ..A..H.     16384  2009-04-11 14:55  例19.24\GetDirectoryInfo\GetDirectoryInfo.suo

     目录          0  2011-08-13 10:30  例19.24\GetDirectoryInfo\GetDirectoryInfo\obj\Debug\TempPE

     目录          0  2011-08-13 10:30  例19.24\GetDirectoryInfo\GetDirectoryInfo\bin\Debug

     目录          0  2011-08-13 10:30  例19.24\GetDirectoryInfo\GetDirectoryInfo\obj\Debug

     目录          0  2011-08-13 10:30  例19.24\GetDirectoryInfo\GetDirectoryInfo\bin

     目录          0  2011-08-13 10:30  例19.24\GetDirectoryInfo\GetDirectoryInfo\obj

     目录          0  2011-08-13 10:30  例19.24\GetDirectoryInfo\GetDirectoryInfo\Properties

     目录          0  2011-08-13 10:30  例19.24\GetDirectoryInfo\GetDirectoryInfo

     目录          0  2011-08-13 10:30  例19.24\GetDirectoryInfo

     目录          0  2011-08-13 10:30  例19.24

............此处省略3个文件信息

评论

共有 条评论

相关资源