Python Directory Which Package to Import

IT IS Easy to create a directory in Python if you know the package you need to import. Packages play a vital role in Python. Create and manipulate directories is simplified in Python with the 'OS' package.


Python Commands
Python Commands

Python Directories

You can create and delete directories in Python. These are the best commands you can use quickly in your projects.



1. How to Create a Directory

Import os 
os.mkdir('datafiles')


2. How to Change Directory

os.chdir('newdirectory')


3. How to Create a Directory and then Create a file in it

import os 
os.mkdir('datafiles/newfiles'); 
os.chdir('datafiles/newfiles'); 
fp=open('input.txt', 'w') 
fp.write('Hello, Welcome to Programming in Python') 
fp.close()


4. How to Know Present Working Directory

os.getcwd()


5. How to delete the directory

os.rmdir('directoryname')


6. How to get the List of Directories

os.listdir()



Keep Reading

Comments

Popular Posts

How to Fix Python Syntax Errors Quickly

7 AWS Interview Questions asked in Infosys, TCS

Python 'getsizeof' Command the Real Purpose

Hyperledger Fabric: 20 Real Interview Questions

How to Decode TLV Quickly

AWS Vs Azure Load Balancers Top Insights

How to Use the ps Command in Linux

QlikView Server vs Publisher Top Differences Really Useful to Your Project

Top 10 SCALA Quiz Questions for Programmers

Python Syntax Errors Cheat Sheet