Easy way to rename files

Renaming the file seems to be more frequent than expected in business, so I will write it as a memorandum.

import os
import glob

N = 8 #Delete 8 characters to delete YYYYMMDD from the file name
EXT = "*.txt"
DIR = r"C:\Users\dirname" #The file path prefix "r" may not be needed.

os.chdir(DIR)
for file in glob.glob(EXT):
    os.rename(file,file[N:])

Recommended Posts

Easy way to rename files
Easy way to customize Python import
Rename YYYYMMDD format files to serial numbers
Easy way to use Wikipedia in Python
[HOW TO] Easy way to debug when generating PDF files with PHP etc.
Easy way to use Python 2.7 on Cent OS 6
Easy way to plot HR diagram using astroquery
Easy way to load CPU / memory on Linux
[Small story] Easy way to convert Jupyter to PDF
An easy way to call Java from Python
Easy to use Flask
Easy to use SQLite3
Easy way to check the source of Python modules
Easy way to scrape with python using Google Colab
An easy way to create an import module with jupyter
Easy to read control flow
Easy to make with syntax
[Python] An easy way to visualize energy data interactively [plotly.express]
[Python] Another way to import
Easy to use E-Cell 4 Intermediate
A relatively easy way to insert a NEologd dictionary on Windows-System Dictionary
PyArmor ~ Easy way to encrypt and deliver python source code ~
An easy way to hit the Amazon Product API in Python
An easy way to re-execute a previously executed command in ipython
Easy to use E-Cell 4 Beginner's edition
Easy copy to clipboard on Linux
Django1.11.1 Image uploader Easy to stumble
Use Flask to run external files
Easy to install pyspark with conda
Easy to use E-Cell 4 Advanced Edition
Bring files in Windows to WSL
Easy to use Jupyter notebook (Python3.5)
Easy to see difference of json
Easy to draw graphs with matplotlib
Easy Python to learn while writing
The fastest way to try EfficientNet
The easiest way to make Flask
The easiest way to try PyQtGraph
[Python Tutorial] An Easy Introduction to Python
Easy way to enter and execute AtCoder test cases in Jupyter Notebook