public void Rename() { if (RenameInputField.text.Trim() != string.Empty && CurrentlySelected != null && RenameInputField.text.IndexOfAny(new char[] { '/', '\\', '?', '%', '*', ':', '|', '"', '<', '>' }) == -1) { RectTransform _CurrentRect = CurrentlySelected.gameObject.GetComponent <RectTransform>(); string _text = _CurrentRect.Find("Text").gameObject.GetComponent <Text>().text; string dirfullpath = _FB.GetDirectoryPath(_text); if (dirfullpath != null) { DirectoryInfo _current = new DirectoryInfo(dirfullpath); DirectoryInfo[] _currentChilds = _current.GetDirectories(); FileInfo[] _currentFiles = _current.GetFiles(); DirectoryInfo _new = new DirectoryInfo(NewFolder(RenameInputField.text)); for (int i = 0; i < _currentChilds.Length; i++) { System.IO.Directory.Move(_currentChilds[i].FullName, _new.FullName + "\\" + _currentChilds[i].Name); } for (int i = 0; i < _currentFiles.Length; i++) { System.IO.Directory.Move(_currentFiles[i].FullName, _new.FullName + "\\" + _currentFiles[i].Name); } System.IO.Directory.Delete(_current.FullName); } else { string filefullpath = _FB.GetFilePath(_text); if (filefullpath != null) { FileInfo _file = new FileInfo(filefullpath); string _New = RenameInputField.text; int iTry = 0; while (_FB.GetFilePath(_New) != null) { _New = RenameInputField.text + " (" + iTry + ")"; iTry++; } byte[] fileData = new byte[_file.Length]; FileStream fs = _file.OpenRead(); fs.Read(fileData, 0, (int)_file.Length); fs.Dispose(); System.IO.File.WriteAllBytes(_FB.GetCurrentDirectory().FullName + "\\" + _New + _file.Extension, fileData); System.IO.File.Delete(_file.FullName); } } _FB.Refresh(); RefreshButtons(); } WaitForNewName(); RenameInputField.text = string.Empty; }