Advertisement
Guest User

Untitled

a guest
Mar 6th, 2015
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. try
  2. {
  3. // make the destination root the current working directory
  4. Environment.CurrentDirectory = target.FullName ;
  5. // enumerate over the files in the source directory
  6. foreach ( FileInfo fi in source.EnumerateFiles() )
  7. {
  8. // parse a datetime out of the file name
  9. DateTime? timestamp = fi.TimestampFromName() ;
  10.  
  11. // construct the relative path of the archive subdirectory
  12. // and ensure that it exists
  13. string relativeSubdir = timestamp.Value.ToString("yyMM\yyMMdd") ;
  14. DirectoryInfo subdir = target.CreateSubdirectory( relativeSubdir ) ;
  15.  
  16. // build a relative path to the file's desired location
  17. // and move it there.
  18. string destination = Path.Combine( relativePath , fi.Name ) ;
  19. fi.MoveTo( destination ) ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement