- Home /
Is there a way to load different drives on a Mac?
Macs are so foreign to me that I don't even know if they have drives in the same way that Windows computers do, but nonetheless:
The program I'm developing is capable of loading external files through a custom file explorer. On Windows, this file explorer allows the user to change drives though a Text Field. The user enters in the letter of the drive they want ('C:\', 'F:\', etc.) and that directory gets loaded into the explorer. The code for this feature is shown below:
public void changeDrive()
{
if (!driveInput.text.Equals(""))
{
string[] drives = Directory.GetLogicalDrives();
//Get the first letter from the Text Field, and append ':\\' to it
string sub = (driveInput.text.Substring(0, 1) + ":\\").ToUpper();
driveInput.text = "";
bool foundDrive = false;
foreach (string drive in drives)
if (sub.Equals(drive))
foundDrive = true;
if(foundDrive == false)
{
Debug.Log("Drive not found.");
bool isLetter = false;
char[] alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();
//Check if the drive loading failed because the user didn't enter a letter
foreach (char letter in alpha)
{
if (sub.Contains(letter))
isLetter = true;
}
if (isLetter)
driveText.text = "Drive " + sub + " could not be found";
else
driveText.text = "Not a valid drive";
}
else
{
Debug.Log("Drive found.");
Debug.Log("Loading directory...");
if (Directory.Exists(sub))
{
showFiles(sub);
Debug.Log("Directory loaded");
driveText.text = "";
}
else
{
Debug.Log("Directory could not be loaded.");
driveText.text = "Drive " + sub + " could not be loaded";
}
}
}
}
While I know this code works on Windows, I'm not sure what the corresponding code would look like for a Mac. I know that I can use '#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN' to differentiate between code intended for Windows computers and Mac computers, but I'm just not sure what that code should actually be. Could anyone who's familiar with Mac file structures help me out?
Your answer
Follow this Question
Related Questions
Mac build not run on other users mac 1 Answer
Black screen while launching editor on Mac (high sierra) 2 Answers
EditorUtility.OpenFilePanel uses \ FileInfo.Name uses / 0 Answers
Xbox One/360 Controller trigger input drops out Mac OSX 0 Answers
Is there a hack/workaround to make OSX builds have Retina support? 2 Answers