Copy Directories in a .build.cs

Hii,

I’m trying to copy the imitation/ folder I have at the root of my executable in the packaged build for now I’ve done this :

here’s the structure of my imitation/ folder :

C:.
├───images
└───Model
    ├───model_barry
    ├───model_cortana
    ├───model_dombasle
    ├───model_frederic
    ├───model_pierre
    └───model_tatiana

Here’s my Plugin.build.cs :

// Recursive method to copy Imitation folder contents
void CopyFolderContents(string sourceDir, string targetDir)
{
  // If directory does not exist, create it
  if (!Directory.Exists(targetDir))
    Directory.CreateDirectory(targetDir);

  // Copy files
  foreach (string filePath in Directory.GetFiles(sourceDir))
  {
    string fileName = Path.GetFileName(filePath);
    string targetFilePath = Path.Combine(targetDir, fileName);
    File.Copy(filePath, targetFilePath, true);

    // Add the copied file as a runtime dependency
    RuntimeDependencies.Add(targetFilePath);
  }

  // Recursively copy subdirectories
  foreach (string subDirPath in Directory.GetDirectories(sourceDir))
  {
    string subDirName = Path.GetFileName(subDirPath);
    string targetSubDirPath = Path.Combine(targetDir, subDirName);
    CopyFolderContents(subDirPath, targetSubDirPath);
  }
}



public ImitationLib(ReadOnlyTargetRules Target) : base(Target)
{
	PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;
	bUseRTTI = true;
	bEnableExceptions = true;

	PublicIncludePaths.AddRange(
new string[] {
	// ... add public include paths required here ...
}
);


	string PluginDir = Path.Combine(ModulePath, "../../Binaries");

	if (Target.Platform == UnrealTargetPlatform.Win64)
	{
		//Get the directory of the plugin binaries
		string PluginBinariesDir = Path.Combine(PluginDirectory, "Binaries", "Win64");
		string PluginModelDir = Path.Combine(PluginDirectory, "imitation");
    ////copy the content of the imitation folder
    //foreach (string filePath in Directory.GetFiles(PluginModelDir))
    //{
    //  // Get the filename from the path
    //  string fileName = Path.GetFileName(filePath);

    //  // Add the dlls as a runtime dependency
    //  RuntimeDependencies.Add("$(TargetOutputDir)\\imitation\\" + fileName, filePath);
    //}

		// Add each dll in the directory as a runtime dependency
		foreach (string filePath in Directory.GetFiles(PluginBinariesDir))
		{
			// Get the filename from the path
			string fileName = Path.GetFileName(filePath);

			// Add the dlls as a runtime dependency
			if (fileName.Contains("imitation") || fileName.Contains("juce") || fileName.Contains("ipp"))
				RuntimeDependencies.Add("$(TargetOutputDir)\\" + fileName, filePath);
		}

		CopyFolderContents(PluginModelDir, "$(TargetOutputDir)\\imitation\\");
  }

It effectively creates me an imitation Folder and the .xml is at the root of it
But it just put me the images folder/ at the root of my imitation folder instead of creating images/ and put them here, it creates correctly a folder Models/ but every person is placed at its root instead of a specified folder :

This fixed it :

void CopyFolderContents(string sourceDir, string targetDir, string relativePath = "")
{
  // If directory does not exist, create it
  if (!Directory.Exists(targetDir))
    Directory.CreateDirectory(targetDir);

  // Copy files
  foreach (string filePath in Directory.GetFiles(sourceDir))
  {
    string fileName = Path.GetFileName(filePath);
    string targetFilePath = Path.Combine(targetDir, relativePath, fileName);

    // Add the file as a runtime dependency
    RuntimeDependencies.Add(targetFilePath, filePath);
  }

  // Recursively copy subdirectories
  foreach (string subDirPath in Directory.GetDirectories(sourceDir))
  {
    string subDirName = Path.GetFileName(subDirPath);
    string subDirRelativePath = Path.Combine(relativePath, subDirName);
    string targetSubDirPath = Path.Combine(targetDir, subDirRelativePath);
    CopyFolderContents(subDirPath, targetDir, subDirRelativePath);
  }
}




public ImitationLib(ReadOnlyTargetRules Target) : base(Target)
{
	PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;
	bUseRTTI = true;
	bEnableExceptions = true;

	PublicIncludePaths.AddRange(
		new string[] {
			// ... add public include paths required here ...
		}
		);


	string PluginDir = Path.Combine(ModulePath, "../../Binaries");

	if (Target.Platform == UnrealTargetPlatform.Win64)
	{
		//Get the directory of the plugin binaries
		string PluginBinariesDir = Path.Combine(PluginDirectory, "Binaries", "Win64");
		string PluginModelDir = Path.Combine(PluginDirectory, "imitation");

		// Add each dll in the directory as a runtime dependency
		foreach (string filePath in Directory.GetFiles(PluginBinariesDir))
		{
			// Get the filename from the path
			string fileName = Path.GetFileName(filePath);

			// Add the dlls as a runtime dependency
			if (fileName.Contains("imitation.dll") || fileName.Contains("imitation.pdb") || fileName.Contains("juce") || fileName.Contains("ipp"))
				RuntimeDependencies.Add("$(TargetOutputDir)\\" + fileName, filePath);
		}
		CopyFolderContents(PluginModelDir, "$(TargetOutputDir)\\imitation\\");
  }

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.