import os
def get_file_extension(file_path):
_, file_extension = os.path.splitext(file_path)
return file_extension
import os
def list_files(directory):
return [file for file in os.listdir(directory) if os.path.isfile(os.path.join(directory, file))]
import os
def join_path(directory, filename):
return os.path.join(directory, filename)
import os
def file_exists(file_path):
return os.path.isfile(file_path)
import os
def directory_exists(directory_path):
return os.path.isdir(directory_path)
import os
def get_current_directory():
return os.getcwd()
def create_directory(path):
if not os.path.exists(path):
os.makedirs(path)
def exists(path):
return os.path.exists(path)
def list_directory_contents(directory):
return os.listdir(directory)
def rename_or_move_file(current_path, new_path):
os.rename(current_path, new_path)
import os
def list_directory_recursively(directory):
paths = []
for root, dirs, files in os.walk(directory):
for name in files:
paths.append(os.path.join(root, name))
for name in dirs:
paths.append(os.path.join(root, name))
return paths
def get_file_size(file_path):
return os.path.getsize(file_path)
def get_last_modification_time(path):
return os.path.getmtime(path)
import os
import time
def change_file_metadata(path, access_time, modification_time):
os.utime(path, (access_time, modification_time))
def find_executable_path(filename):
for path in os.environ["PATH"].split(os.pathsep):
full_path = os.path.join(path, filename)
if os.path.isfile(full_path) and os.access(full_path, os.X_OK):
return full_path
return None
def remove_empty_directory(directory_path):
try:
os.rmdir(directory_path)
return True
except OSError:
return False
import shutil
def copy_directory(source_directory, target_directory):
shutil.copytree(source_directory, target_directory)
def change_permissions(path, mode):
os.chmod(path, mode)
def change_owner(path, uid, gid):
os.chown(path, uid, gid)
def create_symbolic_link(source, target):
os.symlink(source, target)
def get_absolute_path(path):
return os.path.abspath(path)
def get_directory_size(directory):
total_size = 0
for dirpath, dirnames, filenames in os.walk(directory):
for f in filenames:
fp = os.path.join(dirpath, f)
if os.path.exists(fp):
total_size += os.path.getsize(fp)
return total_size