FakeCloneTree
I’ve to test a massive document import from an external system and I want to test on my dev machine before going to the servers. I’ve to deal with filename analysis (the have the key to the business logic of the external legacy system) so I need to clone the client’s storage for a real massive test.
So I decided to build a simple console app to clone the source tree with zero length file (cannot upload 10+gb over the net) to mimic the production environment (to be sure no one file has naming rules nobody told me).
Here the code snapshot. Planning to build a public os utils with zip compression to create a single compressed fake folder tree.
static private void DoClone(string baseFolder, string destinationFolder)
{
// clone folders tree
if (!Directory.Exists(destinationFolder))
Directory.CreateDirectory(destinationFolder);
string[] folders = Directory.GetDirectories(baseFolder);
foreach (var folder in folders)
{
string dn = folder.Remove(0, baseFolder.Length+1);
string dest = Path.Combine(destinationFolder, dn);
if(!Directory.Exists(dest))
Directory.CreateDirectory(dest);
// recursion...
DoClone(folder, dest);
}
// create fake files
string[] files = Directory.GetFiles(baseFolder);
foreach (var file in files)
{
string dest = Path.Combine(destinationFolder, Path.GetFileName(file));
if(!File.Exists(dest))
File.CreateText(dest).Close();
}
}