Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Context: http://www.computercraft.info/forums2/index.php?/topic/44-request-windows-tree-command/
- local tArgs = { ... }
- local currentPath = shell.resolve(".")
- local lineCounter = 0
- local pageFlip = false
- local askingForHelp = false
- --[[ Process command line arguments ]]
- if #tArgs > 1 then -- More than one argument.
- if ( tArgs[1] == string.lower( "-m" ) ) or ( tArgs[1] == string.lower( "-more" ) ) then
- pageFlip = true
- currentPath = shell.resolve( tArgs[2] )
- elseif ( tArgs[2] == string.lower( "-m" ) ) or ( tArgs[2] == string.lower( "-more" ) ) then
- pageFlip = true
- currentPath = shell.resolve( tArgs[1] )
- else
- currentPath = shell.resolve( tArgs[1] )
- end
- else -- Only one argument.
- if ( tArgs[1] == string.lower( "-h" ) ) or ( tArgs[1] == string.lower( "-help" ) ) then
- askingForHelp = true
- elseif tArgs[1] ~= nil then
- currentPath = shell.resolve( tArgs[1] )
- end
- end
- function printUsage()
- print( "Usage: tree [-more] [-help] [<DIRECTORY>]\n" )
- print( "-m or -more Enable page flipping." )
- print( "-h or -help Show this help." )
- print( "<DIRECTORY> Name of the directory." )
- print( " (Default is current directory)" )
- end
- function listDir( path, prefix )
- if path == "" then path = "\\" end -- Path of execution.
- -- Iterate through every element (file or dir) in the path.
- for k, v in pairs( fs.list( path ) ) do
- ---[[ PAGE-FLIP
- if pageFlip then
- lineCounter = lineCounter + 1
- if lineCounter >= 17 then
- write("Press any key to continue")
- read()
- term.setCursorPos( 1, 1 )
- term.clear()
- lineCounter = 0
- end
- end
- --]]
- -- Print file/dir name.
- print( prefix.."-- "..v )
- -- Traverse next directory, if any.
- local nextDir = path.."\\"..v
- if fs.isDir( nextDir ) then listDir( nextDir, prefix.." |" ) end
- end
- end
- if askingForHelp then
- printUsage()
- else
- print( "Listing Directory: "..currentPath )
- listDir( currentPath, "|" )
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement