Garry's Mod Wiki

DFileBrowser

Description

A tree and list-based file browser.

It allows filtering by folder (directory) name and file extension, and can display models as SpawnIcons.

Parent

Derives from DPanel.

Example

Creates a DFileBrowser and displays the data/persist folder. Any file clicked is printed to the console.

local frame = vgui.Create( "DFrame" ) frame:SetSize( 500, 250 ) frame:SetSizable( true ) frame:Center() frame:MakePopup() frame:SetTitle( "DFileBrowser Example" ) local browser = vgui.Create( "DFileBrowser", frame ) browser:Dock( FILL ) browser:SetPath( "GAME" ) -- The access path i.e. GAME, LUA, DATA etc. browser:SetBaseFolder( "data" ) -- The root folder browser:SetOpen( true ) -- Open the tree to show sub-folders browser:SetCurrentFolder( "persist" ) -- Show files from persist function browser:OnSelect( path, pnl ) -- Called when a file is clicked print( path ) end
Output:

Example

Creates a DFileBrowser that can spawn models from props_ folders.

Uses the same DFrame as above
local browser = vgui.Create( "DFileBrowser", frame ) browser:Dock( FILL ) browser:SetPath( "GAME" ) -- The access path i.e. GAME, LUA, DATA etc. browser:SetBaseFolder( "models" ) -- The root folder browser:SetName( "Props_ Models" ) -- Name to display in tree browser:SetSearch( "props_" ) -- Search folders starting with "props_" browser:SetFileTypes( "*.mdl" ) -- File type filter browser:SetOpen( true ) -- Opens the tree (same as double clicking) browser:SetCurrentFolder( "props_badlands" ) -- Set the folder to use function browser:OnSelect( path, pnl ) -- Called when a file is clicked RunConsoleCommand( "gm_spawn", path ) -- Spawn the model we clicked frame:Close() end
Output: See Preview.

Example

Same as above, but enables model viewing. The following line is added to the above code.

browser:SetModels( true ) -- Use SpawnIcons instead of a list
Output:

Page Links


Special Pages


Wikis

?

Render Time: 35ms

DB GetPage 2
Generate Html 9
SaveChanges (1) 12
Render Body 0
Render Sidebar 9