Difference between revisions of "Shell.programs"
From ComputerCraft Wiki
({{delete}} :: does this even exist in CC; and; why is it blank?) |
Digipenguin (Talk | contribs) |
||
| Line 1: | Line 1: | ||
| − | + | Shell.programs is a shell command used in the dir command in default CC | |
| + | |||
| + | function shell.programs( _bIncludeHidden ) | ||
| + | local tItems = {} | ||
| + | |||
| + | -- Add programs from the path | ||
| + | for sPath in string.gmatch(sPath, "[^:]+") do | ||
| + | sPath = shell.resolve( sPath ) | ||
| + | if fs.isDir( sPath ) then | ||
| + | local tList = fs.list( sPath ) | ||
| + | for n,sFile in pairs( tList ) do | ||
| + | if not fs.isDir( fs.combine( sPath, sFile ) ) and | ||
| + | (_bIncludeHidden or string.sub( sFile, 1, 1 ) ~= ".") then | ||
| + | tItems[ sFile ] = true | ||
| + | end | ||
| + | end | ||
| + | end | ||
| + | end | ||
| + | |||
| + | -- Sort and return | ||
| + | local tItemList = {} | ||
| + | for sItem, b in pairs( tItems ) do | ||
| + | table.insert( tItemList, sItem ) | ||
| + | end | ||
| + | table.sort( tItemList ) | ||
| + | return tItemList | ||
| + | end | ||
| + | --[[User:Digipenguin|Digipenguin]] 13:55, 16 April 2013 (MSK) | ||
Revision as of 09:55, 16 April 2013
Shell.programs is a shell command used in the dir command in default CC
function shell.programs( _bIncludeHidden ) local tItems = {}
-- Add programs from the path
for sPath in string.gmatch(sPath, "[^:]+") do sPath = shell.resolve( sPath )
if fs.isDir( sPath ) then local tList = fs.list( sPath ) for n,sFile in pairs( tList ) do if not fs.isDir( fs.combine( sPath, sFile ) ) and (_bIncludeHidden or string.sub( sFile, 1, 1 ) ~= ".") then tItems[ sFile ] = true end end end
end
-- Sort and return local tItemList = {} for sItem, b in pairs( tItems ) do table.insert( tItemList, sItem ) end table.sort( tItemList ) return tItemList end --Digipenguin 13:55, 16 April 2013 (MSK)