-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrefilename.py
More file actions
29 lines (22 loc) · 923 Bytes
/
refilename.py
File metadata and controls
29 lines (22 loc) · 923 Bytes
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
# -*- coding: utf-8 -*-
"""
File function: Batch modify file name
@author: sunlichun
Created on November 10, 2021
"""
import os
# Path of the file to be modified
inputdir = r"D:/A_Postgraduate/Original/true_catalog1/"
def re_filename():
if not os.path.exists(inputdir):
print("file's path not exist"+'\n'+"please enter a correct path")
if os.path.exists(inputdir):
file_list = os.listdir(inputdir)
for i in range(0, len(file_list)):
path = os.path.join(inputdir, file_list[i])
filename = inputdir + os.path.basename(path)
# string format
new_filename = 'ldev_2dimage_bin'+str(os.path.basename(path)).replace('truth_cat4ldev2dimage_bin','')
os.renames(filename, inputdir+format(new_filename))
print("{} file already changed to {}".format(os.path.basename(path),new_filename))
re_filename()