title: FileNotFoundError: [Errno 2] No such file or directory (even though it gives the name of the exact file in the directory)
body: <p>NOTE: I checked all the other locations for similar questions before posting.  This problem did not exist 48 hours ago, and NOTHING has been changed.</p>
  <p>My issue is that I am converting a PDF to TXT so I can take the information and put it into a database.  The 1st script is to convert:</p>
  <pre><code>import PyPDF2
  import os
  import time
  
  #Scan Directory
  
  directory = 'C:\\Users\\Username\\OneDrive\\Desktop\\python'
  for file in os.listdir(directory):
      if not file.endswith(&quot;.pdf&quot;): #Skip non-PDF files
          continue
      with open(os.path.join(directory,file), 'rb') as pdfFileObj:  # Changes here
          pdfReader = PyPDF2.PdfFileReader(pdfFileObj)
          pageObj = pdfReader.getPage(0)
          text=pageObj.extractText()
          print(&quot;Writing File &quot;+ file +&quot; to TXT.&quot;)
          file2=open(r&quot;C:\Users\Username\OneDrive\Desktop\python\\&quot;+file.replace('pdf','txt'),&quot;a&quot;) #Write as TXT files
          file2.writelines(text)
          print(&quot;Done saving.&quot;)
          file2.close()
  </code></pre>
  <p>That part works fine still. It takes 3132019_4102019_1617.pdf and converts it to 3132019_4102019_1617.txt. (This will end up being used to take around 200+ pdfs and covert them). The 2nd part, the one with an issue now, is stating that the file does not exist.  The only issue is that in-order for it to tell me the name of the file not existing, the file itself has to exist.</p>
  <p>The 2nd script (partial):</p>
  <pre><code>import os
  import time
  #import sys
  import mysql.connector
  from collections import deque
  from itertools import groupby
  
  
  directory = 'C:\\Users\\Username\\OneDrive\\Desktop\\python'
  for file in os.listdir(directory):
      if file.endswith(&quot;.txt&quot;): #Skip non-TXT files
          with open(file, 'r') as f:
              nameList = [line.strip() for line in f]
              transferlist = nameList
              char_list=['UPS A','PDU A1','PDU B1','CRAC 03','PDU A2','CRAC 05','UPS B',
              'PDU B2','CRAC 06','CRAC 07','PDU A4','DC CNC','ATS 1','ATS 2','CRAC 02','CRAC 04','CRAC 01',
              'CRAC 09','CRAC 08','CRAC 10','CRAC 11','ATS','DC A1','DC B1','PDU A4''a','b','c','d','e',
              'f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v',
              'w','x','y','z','/',':']
              transferlist2=[ele for ele in transferlist if all(ch not in ele for ch in char_list)]
  
    File &quot;c:\Users\Username\OneDrive\Desktop\python\CLT4_SQL_Insert_3132019_4102019_1617.py&quot;, line 12, in &lt;module&gt;
      with open(file, 'r') as f:
  FileNotFoundError: [Errno 2] No such file or directory: '3132019_4102019_1617.txt'
  </code></pre>
  <p>If I remove the .txt file then the script just runs and closes without doing anything, no errors.  I don't ever call which .txt file to look for as their will be many and it is supposed to do all of them.  The fact that it specifically can grab the name of the .txt file means it does exist, unlike what it states. It worked flawlessly 48 hours ago and everything is located in the exact same folder.</p>