You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Created code for that and extending from outside the code (static)
Wanted to contribute and open PR but I see there ois no code in the repo, attach it here @jeffjadulco
public class DuplicateAndRegenerateGUIDFolder
{
[MenuItem("Assets/Regenerate GUID/ Duplicate and Regenerate GUID for Folder")]
public static void CopyRegenerateAndPasteFolder()
{
var selectedGUIDs = Selection.assetGUIDs;
if (selectedGUIDs.Length == 0 || !AssetGUIDRegeneratorMenu.RegenerateGUID_Validation())
{
Debug.LogWarning("No valid folder selected.");
return;
}
var selectedPath = AssetDatabase.GUIDToAssetPath(selectedGUIDs[0]);
if (!File.GetAttributes(selectedPath).HasFlag(FileAttributes.Directory))
{
Debug.LogWarning("Selected asset is not a folder.");
return;
}
var folderTempPath = Path.Combine(Application.temporaryCachePath, Path.GetFileName(selectedPath));
var newFolderName = Path.GetFileName(folderTempPath) + "_Copy";
if (Directory.Exists(newFolderName) || Directory.Exists(folderTempPath))
{
Debug.LogWarning($"A folder with name {newFolderName} already exists in the destination.");
DeleteTempFolder(folderTempPath);
return;
}
CopyDirectory(selectedPath, folderTempPath);
AssetGUIDRegeneratorMenu.RegenerateGUIDWithFolders_Implementation();
var parentDirectory = Directory.GetParent(selectedPath).FullName;
PasteFolder(folderTempPath, parentDirectory);
DeleteTempFolder(folderTempPath);
}
private static void DeleteTempFolder(string folderCopyPath)
{
if (Directory.Exists(folderCopyPath))
{
Directory.Delete(folderCopyPath, true);
}
}
private static void CopyDirectory(string sourceDir, string destinationDir)
{
Directory.CreateDirectory(destinationDir);
foreach (var file in Directory.GetFiles(sourceDir))
{
var dest = Path.Combine(destinationDir, Path.GetFileName(file));
File.Copy(file, dest);
}
foreach (var dir in Directory.GetDirectories(sourceDir))
{
var dest = Path.Combine(destinationDir, Path.GetFileName(dir));
CopyDirectory(dir, dest);
}
}
private static void PasteFolder(string sourceDir, string destinationParent)
{
var newFolderName = Path.GetFileName(sourceDir) + "_Copy";
var newFolderPath = Path.Combine(destinationParent, newFolderName);
if (Directory.Exists(newFolderPath))
{
Debug.LogWarning($"A folder with name {newFolderName} already exists in the destination.");
return;
}
CopyDirectory(sourceDir, newFolderPath);
AssetDatabase.Refresh();
}
}
The text was updated successfully, but these errors were encountered:
Created code for that and extending from outside the code (static)
Wanted to contribute and open PR but I see there ois no code in the repo, attach it here
@jeffjadulco
The text was updated successfully, but these errors were encountered: