filter files when a filemanager is called from a StringProperty FILE_PATH subtype ?

I understand I can define a file filter_glob property when writing my own operator.
can I do the same when using the FILE_PATH subtype of stringproperty ?

ok, please find below a snippet for review/improvements/better code.

it’s for loading a kind of file from a script panel.

it shows something that looks like a “stringproperty subtype=FILE_PATH” button to load a file or type a filepath, but that can filterfile extension and also report warning/error messages in the gui, with some common tests you have to do on such case.

I did this because :
. I don’t know how to filter files from a stringproperty subtype=FILE_PATH,
. I don’t know how to report ‘out of context’ in the blender ui report area.

import bpy

def loadText(self,context) :
    if f != bpy.context.scene.myvars.pfile :
        # '' check
        if f == '' :
   = 'ERROR', msg = 'Type something please' )
        # ext check
        elif f.split('.')[-1] != 'txt' :
   = 'ERROR', msg = 'not a text file' )
        else :
            # file check
            try : 
                file = open(f, 'r')
                try :['mytextfile'])
                except : pass
                pgnblock =
       = 'mytextfile'
                bpy.context.scene.myvars.pfile = f
                bpy.context.scene.myvars.filepath = f
       = 'INFO', msg = '%s loaded'%f )
            except :
       = 'ERROR', msg = 'Wrong path or corrupted file' )
        bpy.context.scene.myvars.filepath = bpy.context.scene.myvars.pfile

class MyVars(bpy.types.PropertyGroup) :
    pfile = bpy.props.StringProperty()
    filepath = bpy.props.StringProperty(description="Select a text file", update=loadText)

class MyVarsPanel(bpy.types.Panel) :

    bl_label = 'my panel'
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'TOOLS'
    bl_idname = 'MyPanel'

    def draw(self, context):
        myvars = bpy.context.scene.myvars
        layout  = self.layout
        row = layout.row(align=True)
        row.alignment = 'CENTER'
        row.operator( "myvars.load",text='',icon='FILESEL')
        row.operator( "myvars.unload",text='',icon='X')

class MyVarsLoad(bpy.types.Operator) :
    '''Load a TXT file.'''
    bl_idname = 'myvars.load'
    bl_label = 'load a txt file through blender file manager'

    filepath = bpy.props.StringProperty(subtype="FILE_PATH")
    filter_glob = bpy.props.StringProperty(default="*.txt", options={'HIDDEN'})

    def execute(self, context):
        return {'FINISHED'}

    def invoke(self, context, event):
        return {'RUNNING_MODAL'}

class MyVarsUnload(bpy.types.Operator) :
    '''remove the TXT file.'''
    bl_idname = 'myvars.unload'
    bl_label = 'remove the txt file'
    def poll(context,self) :
        return 'mytextfile' in
    def execute(self, context):
        bpy.context.scene.myvars.pfile = ''
        bpy.context.scene.myvars.filepath = ''['mytextfile'])
        return {'FINISHED'}

class MyVarsReport(bpy.types.Operator) :
    '''popup a message'''
    bl_idname = ''
    bl_label = 'Report logs in the gui'
    icon = bpy.props.StringProperty()
    msg = bpy.props.StringProperty()

    def draw(self, context):
        layout = self.layout
        row = layout.split(0.20)
        try : row.label( text = '', icon = self.icon)
        except : pass

    def execute(self, context):
        return context.window_manager.invoke_popup(self)

def register() :
    bpy.types.Scene.myvars= bpy.props.PointerProperty(type=MyVars)

def unregister() :
    bpy.types.Scene.myvars= bpy.props.PointerProperty(type=MyVars)

if __name__ == '__main__' :

anyone has something simpler (should be) ?

your not using OS here ?
interesting i can read a file in local folder on vista WOW nice one man

note i tried with your global filter and seems to work fine?
tried for txt or py file and it filters out quit well on vista

so what else do you want to do here?

thanks for sharing and finding a way to read local files on vista !

wish this could be use with ordinary file read !

happy 2.5

yeah I know it work ricky but it’s so a waste of lines for two simple features :
filtering from subtype=FILE_PATH does not seem to exist,
gui report seems unavailable because of contexts mecanism (but I like it, I like this context thing, don’t ban me… it’s great but in some occasions, how to say that…)