Difference between revisions of "Shell.programs"

From ComputerCraft Wiki
Jump to: navigation, search
(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.)
Line 1: Line 1:
 +
{{Stub}}
 +
{{NeedsWork}}
 
Shell.programs is a shell command used in the dir command in default CC
 
Shell.programs is a shell command used in the dir command in default CC
  
<nowiki>function shell.programs( _bIncludeHidden )
+
== Example ==
local tItems = {}
+
<code>
+
function shell.programs( _bIncludeHidden ) <br/>
-- Add programs from the path
+
    local tItems = {} <br/>
     for sPath in string.gmatch(sPath, "[^:]+") do
+
    sPath = shell.resolve( sPath )
+
    -- Add programs from the path <br/>
if fs.isDir( sPath ) then
+
     for sPath in string.gmatch(sPath, "[^:]+") do <br/>
local tList = fs.list( sPath )
+
        sPath = shell.resolve( sPath ) <br/>
for n,sFile in pairs( tList ) do
+
        if fs.isDir( sPath ) then <br/>
if not fs.isDir( fs.combine( sPath, sFile ) ) and
+
            local tList = fs.list( sPath ) <br/>
  (_bIncludeHidden or string.sub( sFile, 1, 1 ) ~= ".") then
+
            for n,sFile in pairs( tList ) do <br/>
tItems[ sFile ] = true
+
                if not fs.isDir( fs.combine( sPath, sFile ) ) and <br/>
end
+
                    (_bIncludeHidden or string.sub( sFile, 1, 1 ) ~= ".") then <br/>
end
+
                    tItems[ sFile ] = true
end
+
                end
 +
            end
 +
end
 
     end
 
     end
  
 
-- Sort and return
 
-- Sort and return
local tItemList = {}
+
    local tItemList = {}
for sItem, b in pairs( tItems ) do
+
    for sItem, b in pairs( tItems ) do
table.insert( tItemList, sItem )
+
        table.insert( tItemList, sItem )
end
+
    end
table.sort( tItemList )
+
    table.sort( tItemList )
return tItemList
+
    return tItemList
end</nowiki>
+
end
 +
</code>

Revision as of 09:48, 17 April 2013

This page is a stub.
Please help us by expanding it.
This page needs some serious TLC, stat!

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