Python Scripts
Python Scripts
import os
def current_working_dir():
dir = os.getcwd()
************************************************************
def create_new():
new = "Demo"
os.makedirs('new')
************************************************************
def change():
path = "/home/amitt-ashok/"
os.chdir(path)
os.removedirs('raja')
************************************************************
def list_dir():
path = "/home/amitt-ashok/Downloads"
os.chdir(path)
current = os.getcwd()
file_and_dir = os.listdir()
************************************************************
def create_dir():
os.makedirs('raja/rani', exist_ok=True)
print("Created successfully")
************************************************************
def new_file():
f.write('Hello')
************************************************************
def remove_file():
os.remove('sample.txt')
print("file removed successfully..")
************************************************************
def put_env():
os.putenv('name', 'amitt')
print("name:", os.getenv('name'))
os.putenv('MY_VAR', '1234')
print("MY_VAR:", os.getenv('MY_VAR'))
************************************************************
# Path Manipulation
def path_editor():
working_dir = os.getcwd()
file_name = "demo.txt"
if not os.path.isfile(file_path):
f.write('Hello, World')
# Result is True
# result is False
************************************************************
def system_editor():
print(f"Process ID {os.getpid()}")
************************************************************
def permission_file():
file_name = "demo.txt"
os.chmod(file_name, 0o777)