When extracting file paths, not all but a few results are returned that contain special characters ~$ at the start of the file name. I am looking to compare these file paths with another list, thus the special characters prevent the ability to find a proper match.
The current code:
import os
for path, sub_dirs, files in os.walk(root):
for name in files:
# For each file we find, we need to ensure it is a .docx file before adding
# it to our list
if os.path.splitext(os.path.join(path, name))[1] == ".docx":
document_list.append(os.path.join(path, name))
The majority of results are satisfactory, for example:
X:/Serial Numbers/6200Test Company6275 Documents6275rA_Order_TEST_120221.docx
however there are occasional results of special characters that do not exist in file name:
X:/Serial Numbers/6200Test Company6275 Documents~$75rA_Order_MERZ_120221.docx
Preferably seeking an solution that does not rely on a string replace method.
Thanks!
DoctorDentures is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.