First of all, there is no problem with os.rename.
The problem is that the glob module is misused.
[] glob when processing special characters such asEscape (patchname) must be used.
However, the glob module is usually used to obtain a set of file names from that path using regular expressions. That is, *.txt to get all the txt files in that directory.
If you know a clear file path, as is the case with the questioner, glob is an unnecessary method.
https://docs.python.org/ko/3/library/glob.html
Please refer to the link above for specific instructions.
(_ 64, 86 x) 29 : fedora os, 3.7.2 Draws up : python.
There was no problem in the following cases.
os.rename("/home/allinux/aaaa[.txt", '/home/allinux/bbbb.txt')
Please test the name only and post a problem if there is a problem.
path = root_dir + "/" + '[Notice] 2019.hwp'
print(path)
for f, filename in enumerate(glob.glob(path)):
os.rename(filename, os.path.join(root_dir, 'aaaaa'))
It is not being processed if:
I solved the issue of special characters that I asked you. It was resolved by adding str to the file name without using the glove function.
However,
The file name is 2019 (Amendment 1)_1.hwp It is not renamed in the following cases.
path = str(dir + "/" + str(name))
os.rename(dir+"/"+str(name),dir+"/"+str(d))
name: 2019 (Amendment 1) 1.hwp id: aaa_01 2019 Amendment 1_1.hwp
You want to change from name value to id value. I'm going to give you a space and a space. Is there a way?
© 2024 OneMinuteCode. All rights reserved.