4

Searching and Reading Local Files

In this chapter, we will introduce the basic operations to read information from files, starting with searching and opening files stored in different directories and subdirectories. Then, we'll describe some of the most common file types and how to read them, including formats such as raw text files, PDFs, and Word documents.

The last recipe will search for a word inside different kinds of files, recursively in a directory tree.

In this chapter, we'll cover the following recipes:

  • Crawling and searching directories
  • Reading text files
  • Dealing with encodings
  • Reading CSV files
  • Reading log files
  • Reading file metadata
  • Reading images
  • Reading PDF files
  • Reading Word documents
  • Scanning documents for a keyword

We will ...

Get Python Automation Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.