Projektdateien hinzufügen.
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace DirectoryCopyTool
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static string filetype = "";
|
||||
static int Main(string[] args)
|
||||
{
|
||||
if (args.Length != 3)
|
||||
{
|
||||
Console.WriteLine("Verwendung:");
|
||||
Console.WriteLine("DirectoryCopyTool.exe <Source-Verzeichnis> <Dest-Verzeichnis> <FileType>");
|
||||
return 1;
|
||||
}
|
||||
|
||||
string sourceDirectory = Path.GetFullPath(args[0]);
|
||||
string destinationDirectory = Path.GetFullPath(args[1]);
|
||||
filetype = args[2];
|
||||
|
||||
if (!Directory.Exists(sourceDirectory))
|
||||
{
|
||||
Console.WriteLine("Fehler: Das Source-Verzeichnis existiert nicht:");
|
||||
Console.WriteLine(sourceDirectory);
|
||||
return 2;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
CopyDirectory(sourceDirectory, destinationDirectory);
|
||||
|
||||
Console.WriteLine("Kopiervorgang erfolgreich abgeschlossen.");
|
||||
return 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("Fehler beim Kopieren:");
|
||||
Console.WriteLine(ex.Message);
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
static void CopyDirectory(string sourceDirectory, string destinationDirectory)
|
||||
{
|
||||
// Zielverzeichnis anlegen, falls es noch nicht existiert
|
||||
if (!Directory.Exists(destinationDirectory))
|
||||
{
|
||||
Directory.CreateDirectory(destinationDirectory);
|
||||
}
|
||||
|
||||
// Dateien im aktuellen Verzeichnis kopieren
|
||||
foreach (string sourceFile in Directory.GetFiles(sourceDirectory))
|
||||
{
|
||||
string fileName = Path.GetFileName(sourceFile);
|
||||
string destinationFile = Path.Combine(destinationDirectory, fileName);
|
||||
string ext = Path.GetExtension(fileName);
|
||||
if (ext.ToUpper() == "."+filetype.ToUpper())
|
||||
{
|
||||
File.Copy(sourceFile, destinationFile, true);
|
||||
Console.WriteLine("Kopiert: {0}", sourceFile);
|
||||
}
|
||||
|
||||
// true = vorhandene Datei überschreiben
|
||||
}
|
||||
|
||||
// Unterverzeichnisse rekursiv kopieren
|
||||
foreach (string sourceSubDirectory in Directory.GetDirectories(sourceDirectory))
|
||||
{
|
||||
string directoryName = Path.GetFileName(sourceSubDirectory);
|
||||
string destinationSubDirectory =
|
||||
Path.Combine(destinationDirectory, directoryName);
|
||||
|
||||
CopyDirectory(sourceSubDirectory, destinationSubDirectory);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user