💻
Code Snippet
  • Overview
  • General
    • Anaconda
  • GUI
    • PyQT
      • Qt Design
  • Pandas
    • Read Data
    • Replace
  • Articles
    • Python. PyQt
    • Offline Payment Wallet With Django
    • Documentation Encrypt File
    • Play With Pillow
  • Fontend
    • Snippet
    • Hugo
    • JavaScript
      • Form Validation
  • Finance
    • Library
      • yfinance
  • Notebook
    • Untitled
    • Snippet
  • Python
    • Download file
    • Date and Time
    • Snippet
    • Compile .exe
    • Overview
    • Google
      • Samples for Google Workspace
      • Drive
      • GoogleSheet
    • Virtual environment
    • Database
      • Pickle()
    • Datatypes
      • Excel
      • Dictionary
        • xmltodict()
    • File Handling
      • shutil()
      • Get the File Name
      • Get the Full Path
      • Check the File Size
      • Get File Creation Date
      • Find All File
        • Untitled
    • Dictionary
      • Convert Two Lists
  • Data Science
    • HTTP requests
  • Google Workspace
    • Overview
    • Apps Script
      • ์Note
      • Overview
      • Snippet
        • HTML Service
        • Fetch API
      • Quickstart
      • Google Sheets
        • Overview
          • Snippet
        • Fundamentals
          • Macros & Custom Functions
          • Spreadsheets, Sheets, and Ranges
          • Working with Data
          • Data Formatting
          • Chart and Present Data
        • Built-in Google Services
        • Fetch and format API data
        • Connected Sheets
  • Git
  • Mini Lab
    • Line
    • Python
  • Function
    • Python
      • Date&Time
  • Database
    • SQLite
      • Example
Powered by GitBook
On this page
  • Get the Full Path of the Current Working Directory
  • Example 1: Using pathlib module
  • Example 2: Using os module

Was this helpful?

  1. Python
  2. File Handling

Get the Full Path

PreviousGet the File NameNextCheck the File Size

Last updated 3 years ago

Was this helpful?

Get the Full Path of the Current Working Directory

In this example, you will learn to get the full path of the current working directory.

To understand this example, you should have the knowledge of the following topics:

Example 1: Using pathlib module

import pathlib

// path of the given file
print(pathlib.Path("my_file.txt").parent.absolute())

// current working directory
print(pathlib.Path().absolute())

Output

/Users/username
/Users/username

Example 2: Using os module

import os

// path of the given file
print(os.path.dirname(os.path.abspath("my_file.txt")))

// current working directory
print(os.path.abspath(os.getcwd()))

Output

/Users/username
/Users/username
https://www.programiz.com/python-programming/examples/current-working-directory
Python programming
Python File I/O
Python Directory and Files Management