如何根据文件创建日期在c#中创建文件夹和子文件夹? [英] How to create folder and subfolder in c# based on file creation date?

查看:454
本文介绍了如何根据文件创建日期在c#中创建文件夹和子文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何根据文件创建日期在c#中创建文件夹和子文件夹?



目标文件夹结构将基于每个文件的创建日期,即基于在每个文件的创建日期,应创建子文件夹。

例如:如果文件的创建日期是2012年3月1日,则文件夹结构应为

目标路径> 2012> 03> 01

How to create folder and subfolder in c# based on file creation date?

The destination folder structure will be based on the Creation Date of each file i.e., Based on the creation date of each file, subfolders should be created.
For eg: If the Creation Date of a file is 01-Mar-2012, then the folder structure should be
Destination Path > 2012 > 03 > 01

推荐答案

将创建日期作为DateTime值。

使用Path.Combine生成完整路径:

Get the creation date as a DateTime value.
Use Path.Combine to generate the full path:
string fullPath = Path.Combine(destinationPath, cd.Year.ToString(), cd.Month.ToString(), cd.Day.ToString());



然后只需使用 Directory.Create [ ^ ]创建文件夹。


这篇关于如何根据文件创建日期在c#中创建文件夹和子文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆