OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Extracting file paths, occasionally returns special characters (~$) in file names

  • Thread starter Thread starter DoctorDentures
  • Start date Start date
D

DoctorDentures

Guest
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:

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:

Code:
X:/Serial Numbers/6200\Test Company\6275 Documents\6275rA_Order_TEST_120221.docx

however there are occasional results of special characters that do not exist in file name:

Code:
X:/Serial Numbers/6200\Test Company\6275 Documents\~$75rA_Order_MERZ_120221.docx

Preferably seeking a solution that does not rely on a string replace method.
<p>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.</p>
<p>The current code:</p>
<pre><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))
</code></pre>
<p>The majority of results are satisfactory, for example:</p>
<pre class="lang-none prettyprint-override"><code>X:/Serial Numbers/6200\Test Company\6275 Documents\6275rA_Order_TEST_120221.docx
</code></pre>
<p>however there are occasional results of special characters that do not exist in file name:</p>
<pre class="lang-none prettyprint-override"><code>X:/Serial Numbers/6200\Test Company\6275 Documents\~$75rA_Order_MERZ_120221.docx
</code></pre>
<p>Preferably seeking a solution that does not rely on a string replace method.</p>
 

Latest posts

Top