MCPcopy Index your code
hub / github.com/python-cmd2/cmd2 / do_dir

Method do_dir

examples/python_scripting.py:103–119  ·  view source on GitHub ↗

List contents of current directory.

(self, _args: argparse.Namespace, unknown: list[str])

Source from the content-addressed store, hash-verified

101
102 @cmd2.with_argparser(dir_parser, with_unknown_args=True)
103 def do_dir(self, _args: argparse.Namespace, unknown: list[str]) -> None:
104 """List contents of current directory."""
105 # No arguments for this command
106 if unknown:
107 self.perror("dir does not take any positional arguments:")
108 self.do_help("dir")
109 self.last_result = "Bad arguments"
110 return
111
112 # Get the contents as a list
113 contents = os.listdir(self.cwd)
114
115 for f in contents:
116 self.poutput(f"{f}")
117 self.poutput("")
118
119 self.last_result = contents
120
121
122if __name__ == "__main__":

Callers

nothing calls this directly

Calls 3

perrorMethod · 0.80
do_helpMethod · 0.80
poutputMethod · 0.80

Tested by

no test coverage detected