Difference between revisions of "Shell.programs"
From ComputerCraft Wiki
(Who ever just did that last edit, please make sure you are using SPACES, not TABS. Also, I do not suggest using the nowiki tags. Anyway, it is a bit easier to read now.) |
(Fixed the markup on this page. Don't use <code>, use one space to open code chunks.) |
||
| Line 4: | Line 4: | ||
== Example == | == Example == | ||
| − | + | function shell.programs( _bIncludeHidden ) | |
| − | function shell.programs( _bIncludeHidden ) | + | local tItems = {} |
| − | local tItems = {} | + | -- Add programs from the path |
| − | + | for sPath in string.gmatch(sPath, "[^:]+") do | |
| − | -- Add programs from the path | + | sPath = shell.resolve( sPath ) |
| − | for sPath in string.gmatch(sPath, "[^:]+") do | + | if fs.isDir( sPath ) then |
| − | sPath = shell.resolve( sPath ) | + | local tList = fs.list( sPath ) |
| − | if fs.isDir( sPath ) then | + | for n,sFile in pairs( tList ) do |
| − | local tList = fs.list( sPath ) | + | if not fs.isDir( fs.combine( sPath, sFile ) ) and |
| − | for n,sFile in pairs( tList ) do | + | (_bIncludeHidden or string.sub( sFile, 1, 1 ) ~= ".") then |
| − | if not fs.isDir( fs.combine( sPath, sFile ) ) and | + | |
| − | (_bIncludeHidden or string.sub( sFile, 1, 1 ) ~= ".") then | + | |
tItems[ sFile ] = true | tItems[ sFile ] = true | ||
end | end | ||
end | end | ||
| − | + | end | |
end | end | ||
| − | + | ||
| − | + | -- Sort and return | |
local tItemList = {} | local tItemList = {} | ||
for sItem, b in pairs( tItems ) do | for sItem, b in pairs( tItems ) do | ||
| Line 29: | Line 27: | ||
table.sort( tItemList ) | table.sort( tItemList ) | ||
return tItemList | return tItemList | ||
| − | end | + | end |
| − | + | ||
Revision as of 09:50, 17 April 2013
| This page is a stub. Please help us by expanding it.
|
| This page needs some serious TLC, stat! Please help us by cleaning it, fixing it up, or sparing it some love.
|
Shell.programs is a shell command used in the dir command in default CC
Example
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