Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static DirectoryInfo CreateDateBasedFolderStructure(this DateTime now, DirectoryInfo rootFolder)
- {
- try {
- var result = rootFolder
- .CreateSubdirectory(now.Year.ToString())
- .CreateSubdirectory(now.Month.ToString().PadLeft(2, '0'))
- .CreateSubdirectory(now.Day.ToString().PadLeft(2, '0'));
- return result;
- }
- catch(ArgumentNullException ex)
- {
- // Null path
- throw ex;
- }
- catch(ArgumentException ex)
- {
- // Invalid path
- throw ex;
- }
- catch(DirectoryNotFoundException ex)
- {
- // Missing path
- throw ex;
- }
- catch(PathTooLongException ex)
- {
- // Folder or path name is too long
- throw ex;
- }
- catch(IOException ex)
- {
- // Directory or file cannot be created
- throw ex;
- }
- catch(Exception ex)
- {
- // Any other exception that wasn't already handled
- throw ex;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement