Previously on Zero

The OS library is used to perform some basic configurations in daily work. Therefore, the basic operations of the OS library are recorded.

First, basic usage

## 1. Change current working directory
os.chdir(path)

## 2. View the current working directory
os.getcwd()

## 3. Returns a list of files or folder names that the specified folder contains
os.listdir(path)

Create a folder
os.mkdir(path)

## 5. Open file
os.open()

## 6. Delete files
os.removed()

## 7. Rename
os.rename(src,dst)

## 8. Delete empty directories
os.rmdir(path)
Copy the code

2. Path module

## 1. Return absolute path
os.path.abspath(path)

## 2. Return the filename
os.path.basename(path)

## 3. Return the file path
os.path.dirname(path)

## 4. Check that the path exists
os.path.exists(path)

## 5. Return the real path
os.path.realpath(path)

## 6. Split path into dirName and basename and return a tuple
os.path.split(path)
Copy the code