Displaying Datetime, Working Directory and File Metadata
Welcome to the Displaying Datetime, Working Directory, and File Metadata Practice Lab. In this module, you will be provided with the instructions and devices needed to develop your hands-on skills.
Already have an account? Sign In »

Introduction
Welcome to the Displaying Datetime, Working Directory, and File Metadata Practice Lab. In this module, you will be provided with the instructions and devices needed to develop your hands-on skills.
Learning Outcomes
In this module, you will complete the following exercise:
- Exercise 1 - Displaying Date and Time
- Exercise 2 - Displaying the Working Directory and File Metadata
After completing this lab, you will be able to:
- Use the built-in datetime module to print the time, date, year, month, and day of the week
- Use the built-in os module to display the current working directory, and manipulate the directory name and file name
- Use the built-in os and time modules to print the metadata of a file such as creation date, modified date, and file size
Exam Objectives
The following exam objectives are covered in this lab:
- 6.1 Perform basic operations using built-in modules
- 6.2 Solve complex computing problems by using built-in modules
Lab Duration
It will take approximately 30 minutes to complete this lab.
Exercise 1 - Displaying Date and Time
As you already know, modules in Python are pre-defined, ready-to-use mini programs that can be reused into Python programs to solve a specific purpose. Modules help manage large programs and reduce programming effort.
Python has a lot of built-in modules. You have already explored math and random modules.
The datetime module is another such built-in module that supplies predefined classes and functions for manipulating dates and times. One of the important classes in this module is the date class.
To use the datetime module and its functions, all you need to do is import the module by using the import keyword as follows:
import datetime
Once that is done, you can access all the classes and functions defined in the module using the class name and the dot (.) operator.
In this exercise, you will write a program to print the time, date, year, month, and day of the week using the built-in functions such as datetime.now() and date.strftime() from the datetime module.
Learning Outcomes
After completing this exercise, you will be able to:
- Use the built-in datetime module to print the time, date, year, month, and day of the week
Exercise 2 - Displaying the Working Directory and File Metadata
The os module is a standard utility module in Python that provides functions for interacting with the operating system that Python is running on - be it Windows, Mac, or Linux. It provides built-in functions for using the operating system dependent functionality. For example, you can find important information about your current working directory or about a currently running process.
To use the os module and its functions, first you need to import the module by using the import keyword as follows:
import os
Once that is done, you can access all functions defined in the module using the module name and the dot (.) operator.
You can also use various directory/file manipulation functions. In addition, you can use functions to get file metadata, such as the creation date, last modified date, and size of a file.
In this exercise, you will perform two tasks. In task one, you will learn to write a program to display the current working directory and manipulate the directory name and file name.
In task two, you will write a program to print the metadata of a file such as creation date, modified date, and file size.
Learning Outcomes
After completing this exercise, you will be able to:
- Use the built-in os module to display the current working directory, and manipulate the directory name and file name
- Use the built-in os and time modules to print the metadata of a file such as creation date, modified date, and file size
See the full benefits of our immersive learning experience with interactive courses and guided career paths.