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;
}
C# 在选定文件夹中创建“年,月,日“文件夹
最新推荐文章于 2023-12-05 22:45:59 发布