Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Finding a folder in C#?

Discussion in 'Scripting' started by Endzone, Dec 20, 2015.

  1. Endzone

    Endzone

    Joined:
    Dec 18, 2014
    Posts:
    119
    Hello, so im simply trying to locate a folder and for some reason i canot seem to get it to work could anyone please give me a hand or point me in the right direction as to how i can find specific folders ? - Thanks!
     
  2. buckius82

    buckius82

    Joined:
    Nov 19, 2013
    Posts:
    40
    Unityeditor.Assetdatabase.getsubfolders (string path);
    Using this we can chech a sub directory to see if the next level down contains the folder name by looping through the array that was returned.

    Loop throuth array and check if its write one. If not use the same funtion with the origion path +the subfolders array index to create arrays of lower folders in the hierarchy . You can check as yyou go or you can save all folders in dictionary using the path as the key because no to folders will have same path and the name of the folder as the value. Youu can then querey the dictionary for duplicates and path

    Look at msdn linq also to help with queries.

    Setting up your loops will be the most difficult. I'Ll think about it a while hope this helps

    Using a foreach loop on key, value pair
    This will allow you to not only find folders with same name
    The key is its <string> path
    Assets/Resourses/folderineed
    The value is its <string> name
    Folder I need

    Looping through the hierarchy will be tricky. Not every folder path will have the same depth.

    Foreach key, value pair in the dictionary
     
  3. apsdsm

    apsdsm

    Joined:
    Sep 26, 2013
    Posts:
    56
    Post some code, or explain in more detail what you've tried and how it failed, or else we're just guessing at how to help you :)