views:

32

answers:

1

Hello,

I am using Team foundation system and I have requirement in which I want to copy all the checkout files to a local folder along with the same folder structure using C#. How can I do that?


Huzaifa

A: 

I don't know what you mean by the "checkout files", but if you want to copy a directory you have to:

  1. Recursively enumerate all of the files and folders in the top-level directory.
  2. For each item that you enumerate, either create the folder in the destination directory, or copy the source file to the destination directory hierarchy.

The following will enumerate all of the files and folders in a directory:

static void FullDirList(DirectoryInfo dir, string searchPattern)
{
  Console.WriteLine("Directory {0}", dir.FullName);
  // list the files
  foreach (FileInfo f in dir.GetFiles(searchPattern))
  {
    Console.WriteLine("File {0}", f.FullName);
  }
  // process each directory
  foreach (DirectoryInfo d in dir.GetDirectories())
  {
    FullDirList(d, searchPattern);
  }
}

If you call that with FullDirList("C:\MyProject\", *.*), it will enumerate all of the files.

To create destination folders or copy files, change the calls to Console.WriteLine so that they do the appropriate thing. All you should have to change in the destination file or folder names is the root folder name (that is, if you're copying from C:\MyProject\ to C:\MyProjectCopy\, then the destination files are just f.FullName with the C:\MyProject\ replaced by C:\MyProjectCopy).

Jim Mischel
If you want to copy only the checked out files, then add a condition to only copy the writable files (checkin a file out removes the readonly attribute from a file)
Ewald Hofman