Moving/renaming folder

Hello.

Is there a way to change/rename folder with scripts for example and make Unity to load it properly when these scripts are attached to a Game Objects?

When I rename folder or move scripts to another I get “The associated script can not be loaded. […]”.

I do this in Unity and outside with moving .meta files too.

Thank you.

Do operations with assets outside of Unity is not recomended, instead, using the class AssetDatabase, and ofcourse, you can do custom inspector/editor tools to improve the management of all kind assets (folders, animatior controllers, materials etc…).
Look to [AssetDatabase ][1] class, and see some classes to build editor tools: [Editor Window][2], [GUILayout][3], [EditorGUILayout][4].

Look at this example script, he creates a window and list all folders of your project:

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

public class FoldersListWindow : EditorWindow
{
	private List<Folder> assetsFolders = new List<Folder>();
	private Vector2 foldersListScroll;

	[MenuItem("Window/FolderList %#o")]
	private static void Init()
	{
		FoldersListWindow window = GetWindow<FoldersListWindow>();
		window.titleContent = new GUIContent { text = "Folder List" };
		window.Show();
	}

	private void OnEnable()
	{
		foreach (string folder in AssetDatabase.GetSubFolders("Assets"))
		{
			assetsFolders.Add(new Folder(folder));
		}
	}

	private void OnGUI()
	{
		GUILayout.BeginArea(new Rect(1f, 1f, Screen.width / 3f, Screen.height), GUI.skin.box);
		foldersListScroll = EditorGUILayout.BeginScrollView(foldersListScroll, true, true);

		DrawFolders(assetsFolders);

		EditorGUILayout.EndScrollView();
		GUILayout.EndArea();
	}

	private void DrawFolders(List<Folder> foldersList)
	{
		for (int i = 0; i < foldersList.Count; i++)
		{
			EditorGUILayout.BeginVertical(GUILayout.Width(Screen.width / 3f));

			foldersList<em>.isFoldoutShown = EditorGUILayout.Foldout(foldersList_.isFoldoutShown, foldersList*.folderName);*_</em>

if (foldersList_.haveSubFolders && foldersList*.isFoldoutShown)
{
EditorGUI.indentLevel++;*_

_ DrawFolders(foldersList*.subFolders);*_

* EditorGUI.indentLevel–;*
* }*

* EditorGUILayout.EndVertical();*
* }*
* }*
}

// THIS CLASS IS USED TO REPRESENT A FOLDER (WITH SUB FOLDERS) IN THE ASSETS FOLDER
public class Folder
{
* public string fullPath;*
* public string folderName;*
* public bool haveSubFolders;*
* public bool isFoldoutShown;*
* public int subFoldersCount;*
* public List subFolders;*

* public Folder(string path)*
* {*
* fullPath = path;*
* folderName = GetOnlyFolderName(fullPath);*
* haveSubFolders = CheckForSubFolders(fullPath);*

* if (haveSubFolders)*
* {*
* subFolders = new List();*
* string[] folders = AssetDatabase.GetSubFolders(fullPath);*

* foreach (string item in folders)*
* {*
* subFolders.Add(new Folder(item));*
* }*

* subFoldersCount = subFolders.Count;*
* isFoldoutShown = true; *
* }*
* else*
* {*
* haveSubFolders = false;*
* subFoldersCount = 0;*
* isFoldoutShown = false;*
* }*
* }*

* private bool CheckForSubFolders(string path)*
* {*
* string[] folders = AssetDatabase.GetSubFolders(path);*
* if (folders.Length > 0)*
* return true;*
* else*
* return false;*
* }*

* private string GetOnlyFolderName(string path)*
* {*
* return path.Substring(path.LastIndexOf(‘/’) + 1);*
* }*
}
Really a bit “complicated”, but it gives you the power of manipulate all assets in a project.
*[1]: https://docs.unity3d.com/ScriptReference/AssetDatabase.html*_
[2]: https://docs.unity3d.com/ScriptReference/EditorWindow.html*_
_[3]: https://docs.unity3d.com/ScriptReference/GUILayout.html*_

_*[4]: https://docs.unity3d.com/ScriptReference/EditorGUILayout.html*_

I suggest to try KrojamSoft BatchRename