Use filemanager to select directory instead of file?
I presume the main question here is selecting a root directory with the FileSelector.
bpy_extras.io_utils.ExportHelper includes FileSelectParams, which when set give the desired functionality.
The first attribute to be set is:
use_filter_folder = True
This will filter anything that is not a folder to the user. This also has the added advantage that the path your script gets back is folder.
You also need to set a file extension type, even though it is not used. It will cause an error on execution. Possible bug?
filename_ext = &quot;.&quot;
This is based on an for general file import - How do I get the filepath when I import a file?
Full sample
import bpy
from bpy_extras.io_utils import ExportHelper
    
import os.path

class ExportOperator(bpy.types.Operator, ExportHelper):
    &quot;&quot;&quot;Operator for setting a directory path.&quot;&quot;&quot;

    #: Name of function for calling the nif export operator.
    bl_idname = &quot;export_scene.folder&quot;

    #: How the nif import operator is labelled in the user interface.
    bl_label = &quot;Export to folder&quot;

    filename_ext = &quot;.&quot;
    use_filter_folder = True

    def execute(self, context):
        userpath = self.properties.filepath
        if(!os.path.isdir(userpath)):
            msg = &quot;Please select a directory not a file\n&quot; + userpath
            self.report({'WARNING'}, msg)

        #Insert the desired logic here to write to the directory.

        return{'FINISHED'}

def menu_func_import(self, context):
    self.layout.operator(
        ExportOperator.bl_idname, text=&quot;Export Scene to folder&quot;)

def register():
    bpy.utils.register_module(__name__)
    bpy.types.INFO_MT_file_import.append(menu_func_import)

def unregister():
    bpy.utils.unregister_module(__name__)
    bpy.types.INFO_MT_file_import.remove(menu_func_import)

if __name__ == &quot;__main__&quot;:
    register()