title: Python os.scandir() returns file or directory not found
body: <p>I am developing a flask app that scans a directory on local disk and performs some file operations. It works very well in Windows, but when I deploy to DigitalOcean (Linux) it gives the following error:</p>
  <pre><code>for file in os.scandir(path):
  FileNotFoundError: [Errno 2] No such file or directory: '/my/directory/path'
  </code></pre>
  <p>The directory created in my Windows is:</p>
  <pre><code>D:\my\directory\path
  </code></pre>
  <p>So when I use the UNIX path for it <code>/my/directory/path</code> because my project is on my D disk so it considers it as root, it works perfectly.</p>
  <p>On Linux, I literally just created the same path <code>/my/directory/path</code>, and it says directory not found.</p>
  <p>Here is my code:</p>
  <pre><code>def get_files(path):
      print(&quot;CHECKING THE PATH: &quot;, path)
      for file in os.scandir(path):
          if os.path.isfile(os.path.join(path, file)):
              print(&quot;FILE YIELDED IS: &quot;, file)
              yield file
  </code></pre>
  <p><em><strong>UPDATE:</strong></em></p>
  <p>The complete log is:</p>
  <pre><code>Job &quot;sync_work_days (trigger: interval[0:00:05], next run at: 2022-07-16 13:08:01 UTC)&quot; raised an exception
  Traceback (most recent call last):
    File &quot;/usr/local/lib/python3.7/site-packages/apscheduler/executors/base.py&quot;, line 125, in run_job
      retval = job.func(*job.args, **job.kwargs)
    File &quot;/app/app/sftp.py&quot;, line 19, in sync_work_days
      for file in get_files(files_path):
    File &quot;/app/app/sftp.py&quot;, line 9, in get_files
      for file in os.scandir(path):
  FileNotFoundError: [Errno 2] No such file or directory: '/tasbiq/files/renault'
  </code></pre>
  <p>The complete function is:</p>
  <pre><code>def sync_work_days():
      files_path = &quot;/tasbiq/files/renault&quot;
  
      print(&quot;FILES LISTED ARE: &quot;, get_files(files_path))
      files = []
      for file in get_files(files_path):
          print(f&quot;STEP 1: {file} is found&quot;)
          files.append(file)
      
      if files == []:
          print(&quot;STEP 1BIS: DIRECTORY EMPTY&quot;)
          return &quot;empty&quot;
      else:
          for f in files:
              if f.name.endswith('.csv'):
                  print(f&quot;STEP 2: CSV FILE {f} FOUND&quot;)
                  randomint = str(random.randint(1000,9999))
                  datenow = str(datetime.now().date())
                  fpath = files_path + '/' + f.name
                  print(f&quot;STEP 2: file path is {fpath}&quot;)
  
                  upload_working_days(fpath)
                  print(&quot;STEP 2BIS: uploading days finished&quot;)
                  newpath = files_path + '/archive/' + f.name + '-' + datenow + '-' + randomint
                  os.rename(fpath, newpath)
                  print(f&quot;STEP 3: file renamed from {fpath} to {newpath}&quot;)
  </code></pre>
  <p><em><strong>UPDATE 2:</strong></em></p>
  <p>I tried the scandir function in a standalone python file and it worked, but it's not working when it's used in the Flask project. FYI: I'm using Docker annd gunicorn. Here's a screenshot of my test:</p>
  <p><a href="https://i.stack.imgur.com/Y7gGP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Y7gGP.png" alt="enter image description here" /></a></p>
  <p><em><strong>UPDATE 3:</strong></em>
  Replicated the exact same function independently and it worked:
  <a href="https://i.stack.imgur.com/6SdrP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6SdrP.png" alt="enter image description here" /></a></p>