title: PyDrive Upload and Remove
body: <p>I am new to Google Drive API and writing a simplest form of a script that automatically upload an image from the local drive on to google drive, then once that image is uploaded, delete the local copy, following is what I have got: </p>
  
  <pre><code>#%%
  import os
  from pydrive.auth import GoogleAuth
  from pydrive.drive import GoogleDrive
  from googleapiclient.http import MediaFileUpload
  g_login = GoogleAuth()
  g_login.LocalWebserverAuth()
  drive = GoogleDrive(g_login)
  
  #%%
  header = 'images/dice'
  path = header + str(i) + '.png'
  file = drive.CreateFile()
  file.SetContentFile(path)
  file.Upload()
  if file.uploaded:
      print("test")
      os.remove(path)
  </code></pre>
  
  <p>however when attempting in deleting the local copy, following error occurs:</p>
  
  <p>PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'images/dice1.png'</p>
  
  <p>I searched it up, thinking it might be the SetContentFile(path) where it did no close the file after Upload(), which according to </p>
  
  <p><a href="https://gsuitedevs.github.io/PyDrive/docs/build/html/pydrive.html" rel="nofollow noreferrer">https://gsuitedevs.github.io/PyDrive/docs/build/html/pydrive.html</a></p>
  
  <p>it should close automatically after upload. </p>
  
  <p>What am I overseeing here? </p>
  
  <p>Note: In the end, I want to use a loop that go through all the files within the directory. </p>
  
  <p>This is the output:</p>
  
  <pre><code>1
  test
  ---------------------------------------------------------------------------
  
  PermissionError                           Traceback (most recent call last)
  
  &lt;ipython-input-21-2aeb578b5851&gt; in &lt;module&gt;
        9 if file.uploaded:
       10     print("test")
  ---&gt; 11     os.remove(path)
       12 
  
  PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'images/dice1.png'
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/ffnuz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ffnuz.png" alt="enter image description here"></a></p>