Category: FileHandling
Python: Get list of files in directory sorted by name
In this article, we will discuss different ways to get list of all files in a directory / folder sorted by name in python. Table of contents Get list of files (file paths) in directory sorted by name. Get list of file names in directory sorted by name. Get list of files (file paths) in …
Python: Get list of files in directory sorted by nameRead More
Python- Find the largest file in a directory
In this article, we will discuss how to find the largest file in a directory and its sub-directories using python. Table of contents Find the largest file in a directory using python. Find the largest file in a directory and its sub-directories using python. Get the largest file in a directory using python In python, …
Find the smallest file in a directory using python
In this article, we will discuss how to find the smallest file in a directory and its sub-directories using python. Table of contents Find the smallest file in a directory using python. Find the smallest file in a directory and its sub-directories using python. Get the smallest file in a directory using python In python, …
Get filename without extension from a path in Python
In this article, we will learn to extract the filename from a give file without the extension of the file. Table Of Contents Using rfind() method : Using splitext() method: Using the split() method: Using Basename() method : Using pathlib.Path.stem() method : A Pathname consists of name of the file, location at which the file …
Get filename without extension from a path in PythonRead More
How to print the contents of a file in Python
In this article, we will learn how to print the contents of a file in python. We will be discussing multiple approaches to print the contents of a file. The file name and its contents which we will be using in the code is as follows, File name: file.txt Contents of the file Advertisements Hello …
Delete a folder that is not empty in Python
Python provides a great communication channel with OS, hence it can delete, move, create files in the system. In this Python tutorial, we will learn about some methods using which we remove/delete a folder that is not empty. Table Of Contents Method 1 : Using shutil module Method 2 : Using OS module Summary Here …
How to delete the contents of a folder in Python?
File handling in Python programming is a skill every python developer must have. In this python article, we will learn to delete the contents of a folder in Python programming language. Table Of Contents Method 1 : Using OS module os.remove() os.unlink() Method 2 : Using shutil module Method 3: Using pathlib module Summary Method …
File Handling in Python
S.NO Python – File handling Tutorials 10.1 How to read a file line by line in Python? 10.2 How to check if a file is empty in Python? 10.3 How to search for strings in a file in Python? 10.4 How to remove a file if exists in Python? 10.5 How to read CSV file …