I was able to call the file browser from Python by referring to a previous question.
I used the following code.
import bpy
Opens a web browser and prints the filepath to console.
#(To see console.. Window >>> Toggle system console
class OpenBrowser(bpy.types.Operator):
bl_idname = "open.browser"
bl_label = "Minimum code to open browser & get filepath"
filepath = bpy.props.StringProperty(subtype="FILE_PATH")
#somewhere to remember the address of the file
def execute(self, context):
display = "filepath= "+self.filepath
print(display) #Prints to console
#Window>>>Toggle systen console
return {'FINISHED'}
def invoke(self, context, event): # See comments at end [1]
context.window_manager.fileselect_add(self)
#Open browser, take reference to 'self'
#read the path to selected file,
#put path in declared string type data structure self.filepath
return {'RUNNING_MODAL'}
# Tells Blender to hang on for the slow user input
bpy.utils.register_class(OpenBrowser)
#Tell Blender this exists and should be used
[1] In this invoke(self, context, event) is being triggered by the below command
#but in your script you create a button or menu item. When it is clicked
Blender runs invoke() automatically.
#execute(self,context) prints self.filepath as proof it works.. I hope.
bpy.ops.open.browser('INVOKE_DEFAULT')
I want to show only folders in the file browser. But with this code, the user can select both files and folders.
And I don't know how to rename the button in the upper right part of the image.
If I could specify the first folder to open, I would like to do that too.

"both files and folders". I want to be able to select"only folders". Do you think that's not possible with Blender's Python? – gncc Jul 21 '21 at 11:38