For directories or file paths on any panel it's key using a StringProperty. In order to get a File Dialog instead of a Folder Dialog, set its subtype
from DIR_PATH
to FILE_PATH
.
path = StringProperty(
name = "",
description="Choose a directory:",
default="",
maxlen=1024,
subtype='DIR_PATH')
As of Blender 2.8x properties should be assigned using a single colon :
path : StringProperty(
name = "",
description="Choose a directory:",
...
subtype='DIR_PATH')
Following example adds a Folder Dialog to the Tool Shelf and prints the path to the console.

Blender 2.8x Update
import bpy
from bpy.props import (StringProperty,
PointerProperty,
)
from bpy.types import (Panel,
Operator,
AddonPreferences,
PropertyGroup,
)
# ------------------------------------------------------------------------
# Scene Properties
# ------------------------------------------------------------------------
class MyProperties(PropertyGroup):
path : StringProperty(
name="",
description="Path to Directory",
default="",
maxlen=1024,
subtype='DIR_PATH')
# ------------------------------------------------------------------------
# Panel in Object Mode
# ------------------------------------------------------------------------
class OBJECT_PT_CustomPanel(Panel):
bl_idname = "OBJECT_PT_my_panel"
bl_label = "My Panel"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "Tools"
bl_context = "objectmode"
def draw(self, context):
layout = self.layout
scn = context.scene
col = layout.column(align=True)
col.prop(scn.my_tool, "path", text="")
# print the path to the console
print (scn.my_tool.path)
# ------------------------------------------------------------------------
# Registration
# ------------------------------------------------------------------------
classes = (
MyProperties,
OBJECT_PT_CustomPanel
)
def register():
from bpy.utils import register_class
for cls in classes:
register_class(cls)
bpy.types.Scene.my_tool = PointerProperty(type=MyProperties)
def unregister():
from bpy.utils import unregister_class
for cls in reversed(classes):
unregister_class(cls)
del bpy.types.Scene.my_tool
if __name__ == "__main__":
register()
Blender 2.7x
import bpy
from bpy.props import (StringProperty,
PointerProperty,
)
from bpy.types import (Panel,
Operator,
AddonPreferences,
PropertyGroup,
)
# ------------------------------------------------------------------------
# UI (settings Class, Panel in Object Mode)
# ------------------------------------------------------------------------
class MySettings(PropertyGroup):
path = StringProperty(
name="",
description="Path to Directory",
default="",
maxlen=1024,
subtype='DIR_PATH')
class OBJECT_PT_my_panel(Panel):
bl_idname = "OBJECT_PT_my_panel"
bl_label = "My Tool"
bl_space_type = "VIEW_3D"
bl_region_type = "TOOLS"
bl_category = "Tools"
bl_context = "objectmode"
def draw(self, context):
layout = self.layout
scn = context.scene
col = layout.column(align=True)
col.prop(scn.my_tool, "path", text="")
# print the path to the console
print (scn.my_tool.path)
# ------------------------------------------------------------------------
# Registration
# ------------------------------------------------------------------------
def register():
bpy.utils.register_module(__name__)
bpy.types.Scene.my_tool = PointerProperty(type=MySettings)
def unregister():
bpy.utils.unregister_module(__name__)
del bpy.types.Scene.my_tool
if __name__ == "__main__":
register()
To collect all images in a folder use os.listdir()
to return a list containing the files in the folder and make sure that the file type is correct. Simplest way is using a list comprehension:
import os
# path to the folder
path = '/home/user/Desktop/'
# collect all OpenExr files
exr_list = [f for f in os.listdir(path) if f.endswith('.exr')]
# iterate through the list
for i in exr_list:
print(os.path.join(path,i))
For more details about Property Appearance as well as on how to create Custom Interfaces, have a look into: How to create a custom UI?