C# 在选定文件夹中创建“年,月,日“文件夹

FolderBrowserDialog folder1 = new FolderBrowserDialog();//创建文件管理器浏览对象
folder1.ShowDialog();
if (folder1.SelectedPath != "")
{
         FilePath = folder1.SelectedPath;//路径选择并赋值路径变量
         txtFilePath.Text = folder1.SelectedPath;
         //SetConfig.UpdateConfig("FilePath", FilePath);
         CreateFile();
}

private void CreateFile()//创建"年,月,日"文件夹
{
            TodayPath = FilePath;
            string current_day = DateTime.Now.ToString("MM-dd");//读取当前时间的月份和日期,如:03-16
            string current_month = DateTime.Now.ToString("MM"); //读取当前时间的月份,如:03
            string current_year = DateTime.Now.Year.ToString(); //读取当前时间的年份,如:2018
            string year_Path = FilePath + "\\" + current_year;
            if (!Directory.Exists(year_Path))   //创建年文件夹
            {
                Directory.CreateDirectory(year_Path);
            }
            string month_Path = year_Path + "\\" + current_month;
            if (!Directory.Exists(month_Path))//创建月文件夹
            {
                Directory.CreateDirectory(month_Path);
            }
            string day_Path = month_Path + "\\" + current_day;
            if (!Directory.Exists(day_Path))    //创建日文件夹
            {
                Directory.CreateDirectory(day_Path);
            }
            TodayPath = day_Path;
 }

猜你喜欢

转载自blog.csdn.net/lvxingzhe3/article/details/121887627
今日推荐