- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create a unique directory name using Python?
You can use the tempfile module to create a unique temporary directory in the most secure manner possible. There are no race conditions in the directory’s creation. The directory is readable, writable and searchable only by the creating user ID. Note that the user of mkdtemp() is responsible for deleting the temporary directory when done with it. To create a new temporary directory, use it as follows −
import tempfile _, temp_dir_path = tempfile.mkdtemp() # Do what you want with this directory # And remove the directory when done
Note that you need to manually delete this directory after you're done with it.
- Related Articles
- How to create a unique temporary file name using Python?
- How to create a directory using Python?
- How to create a directory recursively using Python?
- How to create a zip archive of a directory using Python?
- How to create a Directory using C#?
- How to create a directory using Java?
- How to create a directory hierarchy using Java?
- How to create a Directory recursively using Java?
- How to remove a directory using Python?
- How to create a directory in project folder using Java?
- How to remove a directory recursively using Python?
- How to calculate a directory size using Python?
- How to rename directory using Python?
- How can I create a directory if it does not exist using Python?
- How to create a new directory in Linux using the terminal?

Advertisements