Mac user needing windows code confirmation, please....

Hi, all.

I have a piece of code that functions perfectly on the Mac but with my license being used on my Powerbook and my iMac I am unable to test my stuff in Windows so I just need someone to confirm for me that this code will work on Windows, please…

var separator = (Application.platform == RuntimePlatform.WindowsEditor) ? "\\" : "/";
filename = Application.dataPath + separator + "Resources" + separator + filename;

Thanks in advance

Unless you’ve added your own “Resources” directory to the Windows build, no, that will not work.

Application.dataPath points to the Contents directory on Mac and the Data directory on Windows (which maps to the Contents/Data directory on Mac).

Yo

Yes, the Resources directory needs to exist, that much is true. What I was referring to was the double backslash. I just need to know if this is going to work or wether this concatenation will require the pathname to be

or

I am aware of the use of special characters in strings but don’t just want to use untested code and say: “There you go. hope it works”. Since this and the following is the only code that makes use of the windows filesystem I just wanted to get confirmation from someone that the \ is correctly used in these two situations…

	function ExtractFilename(filepath: String) : String
	{
    	filepath = filepath.Trim();
		if ( filepath.EndsWith("\\") 
		||   filepath.EndsWith("/" ) ) 
		{
			return String.Empty;
		}
 
		var position : int = filepath.LastIndexOf("\\"[0]);
		if (position < 0)
			position  = filepath.LastIndexOf("/"[0]);

so apart from the Resources folder that neds to exist, you are saying the code is okay?

Basically I am trying to recreate Path.GetFileNameWithoutExtension that can be called outside the runtime environment.

use forward slashes.
Win2k, WinXP and onward accept it just as well, no need for backslashes.

now if THAT doesn’t make for cleaner code then nothing will!!!

Thanks very much for that :slight_smile: