0% found this document useful (0 votes)
4 views2 pages

OS Module in Python

The os module in Python allows interaction with the operating system, including functions to get the current working directory, change directories, list files, create and delete folders, and check for the existence of files or directories. Key operations include importing the module, using os.getcwd() to retrieve the current directory, and os.listdir() to list contents. Additional functionalities include creating folders with os.mkdir(), renaming files with os.rename(), and removing files and folders with os.remove() and os.rmdir().

Uploaded by

meavi667
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

OS Module in Python

The os module in Python allows interaction with the operating system, including functions to get the current working directory, change directories, list files, create and delete folders, and check for the existence of files or directories. Key operations include importing the module, using os.getcwd() to retrieve the current directory, and os.listdir() to list contents. Additional functionalities include creating folders with os.mkdir(), renaming files with os.rename(), and removing files and folders with os.remove() and os.rmdir().

Uploaded by

meavi667
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

OS Module in Python

The os module is used to interact with the operating system.

1️⃣Import os module
import os

2️⃣Get current working directory


import os

print([Link]())

👉 Output:

/Users/siddharth/Desktop

3️⃣Change directory
[Link]("/Users/siddharth/Documents")
print([Link]())

4️⃣List files and folders


import os

print([Link]())

Output:

['[Link]', '[Link]', '[Link]']

5️⃣Create a folder
import os

[Link]("demo_folder")

6️⃣Create multiple folders


[Link]("a/b/c")

7️⃣Check file or folder exists


import os

print([Link]("[Link]"))

8️⃣Check file or directory


print([Link]("[Link]"))
print([Link]("demo_folder"))

9️⃣Rename file
[Link]("[Link]", "[Link]")

🔟 Delete file
[Link]("[Link]")

1️⃣1️⃣Delete folder
[Link]("demo_folder")

You might also like