---
title: "How can I delete hidden folders with Python?"  
description: "How can I delete hidden folders with Python?"  
author: "Revati S Misra"  
published: 2023-07-24  
updated: 2023-07-25  
canonical: https://www.mindstick.com/forum/159252/how-can-i-delete-hidden-folders-with-python  
category: "python"  
tags: ["python", "folder"]  
reading_time: 2 minutes  

---

# How can I delete hidden folders with Python?

How can I [delete](https://www.mindstick.com/forum/33620/how-to-delete-record-from-list-in-mvc-using-ajax) [hidden](https://www.mindstick.com/forum/2303/skip-validating-field-from-hidden-div) folders with [Python](https://www.mindstick.com/articles/75378/simple-yet-useful-tips-when-using-python)?

## Replies

### Reply by Aryan Kumar

Sure, here is how you can delete hidden folders with Python:

Python

```plaintext
import os

# Get the current working directory.
current_directory = os.getcwd()

# Get a list of all the files and folders in the current directory.
files_and_folders = os.listdir(current_directory)

# Iterate over the files and folders.
for file_or_folder in files_and_folders:

  # Check if the file or folder is hidden.
  is_hidden = file_or_folder.startswith(".")

  # If the file or folder is hidden, delete it.
  if is_hidden:
    os.removedirs(os.path.join(current_directory, file_or_folder))
```

This code first gets the current working directory using the `os.getcwd()` function. Then, it gets a list of all the files and folders in the current directory using the `os.listdir()` function.

Next, the code iterates over the files and folders in the list. For each file or folder, the code checks if it is hidden by checking if it starts with a `.`. If the file or folder is hidden, the code deletes it using the `os.removedirs()` function.

The `os.removedirs()` function deletes a directory and all of its subdirectories. So, if you call `os.removedirs()` on a hidden folder, it will delete the folder and all of its contents, including any hidden files and folders.


---

Original Source: https://www.mindstick.com/forum/159252/how-can-i-delete-hidden-folders-with-python

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
