Search Unity

split path at 'Assets'

Discussion in 'Scripting' started by topofsteel, Jul 14, 2013.

  1. topofsteel

    topofsteel

    Joined:
    Dec 2, 2011
    Posts:
    999
    I am using 'EditorUtility.OpenFolderPanel' to get a path. Bur it returns the complete path...

    'X:\Projects\4604-Renovation\Unity\4604_02\Assets\Models\FullBuilding\Materials'

    I only want 'Assets\Models\FullBuilding\Materials'

    how can I remove the path up to that point? Thanks.
     
  2. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    I would look into regular expressions
     
  3. tonyd

    tonyd

    Joined:
    Jun 2, 2009
    Posts:
    1,224
    You could also use string slicing, here is a UnityScript example:

    Code (csharp):
    1. function Start(){
    2.     var fullPath = "X:/Projects/4604-Renovation/Unity/4604_02/Assets/Models/FullBuildin g/Materials";
    3.     var shortPath = fullPath[fullPath.IndexOf("Assets"):];
    4.     Debug.Log(shortPath);
    5. }