How do I get the filepath when I import a file?
This general implementation for file based actions is to use in-built mix-in classes, bpy.types.Operator, bpy_extras.io_utils.ImportHelper.
ImportHelper &amp; ExportHelper are wrappers for FileSelector.

import bpy
from bpy_extras.io_utils import ImportHelper, ExportHelper

class NifImportOperator(bpy.types.Operator, ImportHelper):
    """Operator for loading a nif file."""

    #: Name of function for calling the nif export operator.
    bl_idname = "import_scene.nif"

    #: How the nif import operator is labelled in the user interface.
    bl_label = "Import NIF"

    def execute(self, context):
        path = "Importing " + self.properties.filepath
        self.report({'INFO'}, path)
        return{'FINISHED'}


Once your class is registered(see below)), it can be invoked via console.

bpy.ops.&lt;bl_idname&gt;('INVOKE_DEFAULT') 

bpy.ops.import_scene.nif('INVOKE_DEFAULT')


The addition of the ImportHelper/ExportHelper, a new attribute is defined in the self.properties of the operator (filepath).

In the above, because we did not set that attribute, you will get the FileSelector. 
The filepath attribute will be set to the value of the url bar.
Alternative method of invocation via search bar or menu, will produce the same default invocation.

ImportHelper also allows you to pass in an explicit argument "filepath" into the operator.

bpy.ops.&lt;bl_idname&gt;(filepath="") 

bpy.ops.import_scene.nif(filepath="C:\\mypath")


This will skip, the FileSelector.
In either scenario, the execute() method defined in your class is then called.
The filepath is now accessible via
    self.properties.filepath

With this now accessible, you can do whatever you want with it, my sample below just reports it to the info bar.



Full Sample

import bpy
from bpy_extras.io_utils import ImportHelper, ExportHelper

class NifImportOperator(bpy.types.Operator, ImportHelper):
    """Operator for loading a nif file."""

    #: Name of function for calling the nif export operator.
    bl_idname = "import_scene.nif"

    #: How the nif import operator is labelled in the user interface.
    bl_label = "Import NIF"

    def execute(self, context):
        path = "Importing " + self.properties.filepath
        self.report({'INFO'}, path)
        return{'FINISHED'}

def menu_func_import(self, context):
    self.layout.operator(
        NifImportOperator.bl_idname, text="NetImmerse/Gamebryo (.nif)")

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__ == "__main__":
    register()