Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- try
- {
- // make the destination root the current working directory
- Environment.CurrentDirectory = target.FullName ;
- // enumerate over the files in the source directory
- foreach ( FileInfo fi in source.EnumerateFiles() )
- {
- // parse a datetime out of the file name
- DateTime? timestamp = fi.TimestampFromName() ;
- // construct the relative path of the archive subdirectory
- // and ensure that it exists
- string relativeSubdir = timestamp.Value.ToString("yyMM\yyMMdd") ;
- DirectoryInfo subdir = target.CreateSubdirectory( relativeSubdir ) ;
- // build a relative path to the file's desired location
- // and move it there.
- string destination = Path.Combine( relativePath , fi.Name ) ;
- fi.MoveTo( destination ) ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement