# Script Command to "Sort By Name" inside all folders

**URL:** <https://qa.fmod.com/t/script-command-to-sort-by-name-inside-all-folders/20450>\
**Category:** FMOD Studio\
**Created:** [July 21, 2023, 9:42am UTC](https://qa.fmod.com/t/script-command-to-sort-by-name-inside-all-folders/20450 "2023-07-21T09:42:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrybo](https://avatars.discourse-cdn.com/v4/letter/a/c37758/32.png) [@andrybo](https://qa.fmod.com/u/andrybo)\
**Post date:** [July 21, 2023, 9:42am UTC](https://qa.fmod.com/t/script-command-to-sort-by-name-inside-all-folders/20450/1 "2023-07-21T09:42:50Z")

</div>

Is there a script command to sort by name all the folders of the project?  
How can I execute that automatically every time I open the project?

many thanks

---

<div class="post-metadata">

**Author:** ![Leah\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/leah_fmod/32/3685_2.png) [@Leah\_FMOD](https://qa.fmod.com/u/Leah_FMOD)\
**Post date:** [July 24, 2023, 1:55am UTC](https://qa.fmod.com/t/script-command-to-sort-by-name-inside-all-folders/20450/2 "2023-07-24T01:55:47Z")

</div>

Hi,

There’s no single script function to sort all folder in a project by name. However, this can be done by enumerating them, and sorting them yourself by operating on the `ManagedRelationship` of a given folder using the [`ManagedRelationship` functions](https://www.fmod.com/docs/2.02/studio/scripting-api-reference-project-managedobject.html#managedrelationship). For example, I can swap the positions of two events in an event folder that I’ve selected in the event editor with the following:

```auto
var firstEvent = studio.window.browserCurrent().relationships.items.destinations[0];
studio.window.browserCurrent().relationships.items.remove(firstEvent);
studio.window.browserCurrent().relationships.items.insert(1, firstEvent);

```

As for executing script automatically on opening a project, there unfortunately exists no callback for doing so. That said, I’ve noted it on our internal feature/improvement tracker.
