Ignore Directories and Missing Files (Task)

In this task, you’re goal is to make the wordcount command handle directories and missing files gracefully. This is crucial for making your program robust and user-friendly. Instead of failing with an error message when encountering a directory or a non-existent file, your program should report zeros for lines, words, and bytes, along with a descriptive message.

Acceptance Criteria

  • When the path provided as a command-line argument is a directory, your program should output zeros for lines, words, and bytes, followed by the directory name and the message (is a directory).
  • When the specified file doesn’t exist, your program should output zeros for lines, words, and bytes, followed by the missing file name and the message (no such file or directory).
  • For regular files and standard input, the behavior should remain unchanged.

Examples

Given a directory input:

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.