Skip to content

Instantly share code, notes, and snippets.

@fr34kyn01535
Last active September 5, 2015 07:48
Show Gist options
  • Save fr34kyn01535/142a6c0a43bb937d2d1b to your computer and use it in GitHub Desktop.
Save fr34kyn01535/142a6c0a43bb937d2d1b to your computer and use it in GitHub Desktop.
using System.IO;
namespace fr34kyn01535.MapCopy
{
class Program
{
private static string unturnedFolder = @"C:\Users\fr34kyn01535\Desktop\Unturned\Servers\";
private static string instanceName = "cobra1";
static void Main(string[] args)
{
copyInventories("PEI","TEST");
}
private static void copyInventories(string source,string target)
{
string allPlayersFolder = Path.Combine(unturnedFolder, instanceName, "Players");
string[] players = Directory.GetDirectories(allPlayersFolder, "*", SearchOption.TopDirectoryOnly);
foreach (string player in players)
{
string sourceMapPath = Path.Combine(allPlayersFolder, player, source);
string targetMapPath = Path.Combine(allPlayersFolder, player, target);
if (Directory.Exists(sourceMapPath) && !Directory.Exists(targetMapPath))
{
CopyDirectory(sourceMapPath, targetMapPath);
}
}
}
/// <summary>
/// Copies a directory and all subdirectories & files (From https://msdn.microsoft.com/de-de/library/Bb762914(v=VS.110).aspx)
/// </summary>
/// <param name="sourceDirName">Folder to copy the files from</param>
/// <param name="destDirName">Folder to copy the files to, will be created if nonexistent</param>
private static void CopyDirectory(string sourceDirName, string destDirName)
{
DirectoryInfo sourceDirectory = new DirectoryInfo(sourceDirName);
if (!sourceDirectory.Exists)
{
throw new DirectoryNotFoundException();
}
DirectoryInfo[] dirs = sourceDirectory.GetDirectories();
if (!Directory.Exists(destDirName))
{
Directory.CreateDirectory(destDirName);
}
FileInfo[] files = sourceDirectory.GetFiles();
foreach (FileInfo file in files)
{
string temppath = Path.Combine(destDirName, file.Name);
file.CopyTo(temppath, false);
}
foreach (DirectoryInfo subdir in dirs)
{
string temppath = Path.Combine(destDirName, subdir.Name);
CopyDirectory(subdir.FullName, temppath);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment