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.)
(Renamed optional argument)
 
(5 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{Stub}}  
+
{{lowercase}}
{{NeedsWork}}
+
{{Function
Shell.programs is a shell command used in the dir command in default CC
+
|name=shell.programs
 +
|args=[<nowiki/>{{type|boolean}} showHidden]
 +
|returns={{type|table}} programs
 +
|api=Shell
 +
|addon=ComputerCraft
 +
|desc=Returns a table of files in the current directory and in rom/programs. If ''showHidden'' is true, will also return files that begin with a period (hidden files).
 +
|examples=
 +
{{Example
 +
|desc=The program lists files in the current directory and in rom/programs, not including files that are prefixed with a period (hidden files).
 +
|code=textutils.tabulate(shell.programs())
 +
|output=A tabulated list of programs. This is basically the 'programs' program.
 +
}}
 +
{{Example
 +
|desc=The program lists all files in the current directory and in rom/programs.
 +
|code=textutils.tabulate(shell.programs(true))
 +
|output=A tabulated list of programs. This is basically the 'programs' program, but it shows hidden files too.
 +
}}
 +
}}
  
== Example ==
+
[[Category:API_Functions]]
<code>
+
function shell.programs( _bIncludeHidden ) <br/>
+
    local tItems = {} <br/>
+
+
    -- Add programs from the path <br/>
+
    for sPath in string.gmatch(sPath, "[^:]+") do <br/>
+
        sPath = shell.resolve( sPath ) <br/>
+
        if fs.isDir( sPath ) then <br/>
+
            local tList = fs.list( sPath ) <br/>
+
            for n,sFile in pairs( tList ) do <br/>
+
                if not fs.isDir( fs.combine( sPath, sFile ) ) and <br/>
+
                    (_bIncludeHidden or string.sub( sFile, 1, 1 ) ~= ".") then <br/>
+
                    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
+
</code>
+

Latest revision as of 19:29, 4 April 2014


Grid Redstone.png  Function shell.programs
Returns a table of files in the current directory and in rom/programs. If showHidden is true, will also return files that begin with a period (hidden files).
Syntax shell.programs([boolean showHidden])
Returns table programs
Part of ComputerCraft
API Shell

Examples

Grid paper.png  Example
The program lists files in the current directory and in rom/programs, not including files that are prefixed with a period (hidden files).
Code
textutils.tabulate(shell.programs())
Output A tabulated list of programs. This is basically the 'programs' program.



Grid paper.png  Example
The program lists all files in the current directory and in rom/programs.
Code
textutils.tabulate(shell.programs(true))
Output A tabulated list of programs. This is basically the 'programs' program, but it shows hidden files too.