Tuesday, 23 April 2024

OS LIBRARY FUNCTIONS

 

import os

#  1. if you want access the directory  of is current file so

# print(os.getcwd())

# 2. if you want a creat folder in current folder so

# os.mkdir("Test Folder")

# 3. if you want check the exsist of folder so

# print(os.path.exists("Test Folder"))

# 4. if function in is

# if os.path.exists('Test Folder'):
#     print("Already Exists")
# else:
#     print(os.mkdir("Manan"))

# 5. when if we want creat folder in another directory of is PC so

# os.mkdir(r"D:\Import Folder/hanan.txt")

# 6. if you want again folder creat in hanan.txt so

# os.mkdir(r"D:\Import Folder\hanan.txt/wahab.txt")

# 7. if you want access the list of current directory so

# print(os.listdir())

# 8. if you want access the list of another directory so

# print(os.listdir(r"D:\Import Folder"))

#  9. if you want access the folder path so

# for item in os.listdir():
#     path = os.path.join(os.getcwd(),item)
#     print(path)

#  10. if you want access another directory path so

# for item in os.listdir("D:\Import Folder"):
#     path = os.path.join("D:\Import Folder", item)
#     print(path)

#  11. if you want creat a list in folder so
# for i in range(0, 101):
#     os.mkdir(f"D:\Folders/Data {i}")

# 11. if you want change the name of files import folder to data so
 
# for i in range(0, 101):
#     os.rename(f"D:\Import Folder {i}", f"D:\Data {i}")
 
# 12. if you want access the folder list of list so

# manan = os.listdir("D:\Folders")
# print(manan)

#  13. if you want folder see in line by line so

# for hanan in manan:
#     print(hanan)

# 14. if you want see this content in all folders in one by one so

# manan = os.listdir("D:\Folders/")
# for hanan in manan:
#     print(os.listdir(f"D:\Folders/{hanan}"))
#     print(hanan)

# 15. if you want change the drictory of current directory so

# print(os.getcwd())

No comments:

Post a Comment

MAKE A CALANDER

  # 1.  convert calander year and month. your choice month or year , print while True :   import calendar   year = int ( input ( "P...