|
若换行符为\r\n- import os
- for root, dirs, files in os.walk(os.getcwd()):
- for file in files:
- if file.endswith('.php'):
- file_path = os.path.join(root, file)
- with open(file_path, 'rb+') as file:
- file.seek(-4, os.SEEK_END) # Go to the 4th last byte of the file
- last_bytes = file.read(4)
- if last_bytes == b'?>\r\n':
- print(file_path)
- file.seek(-2, os.SEEK_END) # Go to the last 2 bytes (the newline)
- file.truncate()
Copy the Code 若换行符为\n,需将上面的 -4 改为 -3,将4改为3,将?>\r\n改为?>\n,将-2改为-1 |
|