Here I’ll be using os package, it provides operating system interfaces to talk to file system. To read more about it, follow about link.
Start from dirt basics, import os package using : import os
View current working directory path: os.getcwd()
View current directory contents in python: os.listdir()
os.listdir('/Users/username/tasks/')
Change current directory: os.chdir('/home/user/')
os.chdir(os.path.join(os.curdir(), subdirectory_name))
os.path.join(base_path, subdirectory)
: Returns path of subdirectoryos.rename(os.path.join(os.getcwd(),file), os.path.join(os.getcwd(), file.replace('_','-')))
import os
onlyfiles = [f for f in os.listdir() if isfile(f)]
for file in onlyfiles:
os.rename(os.path.join(os.getcwd(),file), os.path.join(os.getcwd(), file.replace('_','-')))