# Script File List

**URL:** <https://forum.inductiveautomation.com/t/script-file-list/17799>\
**Category:** Ignition\
**Tags:** ignition79\
**Created:** [April 22, 2018, 1:15pm UTC](https://forum.inductiveautomation.com/t/script-file-list/17799 "2018-04-22T13:15:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![DavidWisely](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/davidwisely/32/10482_2.png) [@DavidWisely](https://forum.inductiveautomation.com/u/DavidWisely)\
**Post date:** [April 22, 2018, 1:15pm UTC](https://forum.inductiveautomation.com/t/script-file-list/17799/1 "2018-04-22T13:15:39Z")

</div>

Hello,

From within a script, I would like to get a list of all the modules in the project.  
I can get all the imported modules using this:

```auto
	import sys
	for name, module in sys.modules.items():
		if 'project' in name:
			print name

```

but I would like to get a list of all modules (or filenames), even if they haven’t been imported yet.  
As they haven’t been imported, I may need to query the underlying structure where the modules are stored, but I have no idea of how to do this?  
Any ideas?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 22, 2018, 5:26pm UTC](https://forum.inductiveautomation.com/t/script-file-list/17799/2 "2018-04-22T17:26:15Z")

</div>

All modules that have no syntax errors are pre-loaded under the `shared` or `project` names. You should not import them, as you can have problems with code object lifetimes. Place the following in a script module and call it from button:

```auto
from com.inductiveautomation.ignition.common.script import ScriptModule, ScriptPackage

def scripts(modobj=None, depth=""):
	if modobj is None:
		modobj = project
	if isinstance(modobj, ScriptPackage):
		print "%s%s." % (depth, modobj. __name__ )
		for x in dir(modobj):
			scripts(getattr(modobj, x), depth+" ")
	elif isinstance(modobj, ScriptModule):
		print "%s%s" % (depth, modobj. __name__ )

```

Pass `shared` to it to see all of your global scripts, otherwise it defaults to enumerating the project scripts.

---

<div class="post-metadata">

**Author:** ![DavidWisely](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/davidwisely/32/10482_2.png) [@DavidWisely](https://forum.inductiveautomation.com/u/DavidWisely)\
**Post date:** [April 23, 2018, 2:13am UTC](https://forum.inductiveautomation.com/t/script-file-list/17799/3 "2018-04-23T02:13:37Z")

</div>

Awesome! Thanks pturmel,

It seems the problems I was having were due to testing my code in the Script Console where the modules aren’t loaded. Once I called it from a button on a page, as you suggested, it worked well.

I’ve just modified it a bit because I had an error in one of the modules that I’m still working on:

```auto
def scripts(modobj=None, depth=""):
	from com.inductiveautomation.ignition.common.script import ScriptModule, ScriptPackage

	output = ''

	if modobj is None:
		modobj = project
	if isinstance(modobj, ScriptPackage):
		#print "%s%s." % (depth, modobj. __name__ )
		output += "%s%s.\n" % (depth, modobj. __name__ )
		for x in dir(modobj):
			try:
				output += scripts(getattr(modobj, x), depth+" ")
			except:
				output += "%s%s. %s\n" % (depth, modobj. __name__ , 'Error in module!')
	elif isinstance(modobj, ScriptModule):
		#print "%s%s" % (depth, modobj. __name__ )
		output += "%s%s\n" % (depth, modobj. __name__ ) 
		
	return output

```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 23, 2018, 12:08pm UTC](https://forum.inductiveautomation.com/t/script-file-list/17799/4 "2018-04-23T12:08:49Z")

</div>

You should move your import out of the function. Import is a time-consuming operation and should only be called once (on initial script load).

---

<div class="post-metadata">

**Author:** ![DavidWisely](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/davidwisely/32/10482_2.png) [@DavidWisely](https://forum.inductiveautomation.com/u/DavidWisely)\
**Post date:** [April 24, 2018, 12:27am UTC](https://forum.inductiveautomation.com/t/script-file-list/17799/5 "2018-04-24T00:27:28Z")

</div>

Thanks. I’ll do that. Hadn’t really considered it before, but it makes sense. And any improvement to performance is a good thing.
