-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWIN-RENAME.FILES.v2.py
42 lines (42 loc) · 2.51 KB
/
WIN-RENAME.FILES.v2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#--!/usr/bin/env python3
#-- -*- coding: Latin-1 -*-
#--
#-- **************************************************************************************************************:
#-- ************************************************* RENAME FILES ***********************************************:
#-- **************************************************************************************************************:
#-- Author: JBALLARD (JEB) :
#-- Date: 2024.1.05 :
#-- Script: WIN-RENAME.FILES.v2.py :
#-- Dir: \\JBALLARD-9520\C$\0_SVN\2_DEV\3_PYTHON.Src\1_USEFUL.Dev\WINDOWS.Src\FILES.FOLDERS.Src\ :
#-- Purpose: A python script that renames all files within the specified directory. :
#-- Version: 1.0 :
#-- **************************************************************************************************************:
#-- **************************************************************************************************************:
#--
#-- ********************************************************:
#-- DEFINE PARAMS, CONSTANTS, CONFIG PATHS, CLASSES :
#-- ********************************************************:
import os
#--
FILEExt = [".txt", "jeb", ".pdf", ".docx", ".doc"]
#--
#-- FUNCTION - RENAME FILES IN DIR:
def rename_files(directory):
for filename in os.listdir(directory):
#-- FILTER FILES USING BELOW REQUIREMENTS:
if (filename.startswith("MATHEMATICS-") and
any(extension in filename for extension in FILEExt)):
#-- REPLACE FILES USING BELOW REQUIREMENTS:
NEWFName = "MATH-" + filename[12:]
FILESDir = os.path.join(directory, filename)
NEWFILESDir = os.path.join(directory, NEWFName)
#-- RENAME FILES:
os.rename(FILESDir, NEWFILESDir)
print(f"NOTE - RENAMED {FILESDir} TO {NEWFILESDir}:")
#--
#-- DIRECTORY:
rename_files("//JBALLARD-9520/C$/0_SVN/1_DOCS/SELF.DEVELOPMENT.Doc/MATHEMATICS")
#--
#-- ********************************************************:
#-- END OF PYTHON SCRIPT :
#-- ********************************************************: