title: Ttrying to copy the content of files from source to destination, if file is .txt and if files have the same names and then ZIP each just copied file
body: <p>I'm new to python and trying to copy the content of files from dir_A to dir_B. If file is .txt and if these files from dir_A and dir_B have the same names and after <strong>zip</strong> each of these newly copied files.</p>
  <pre><code>import os, shutil, zipfile
  
  src_folder = &quot;C:/Users/pushka/pythonApp1/src_folder&quot;
  dst_folder = &quot;C:/Users/pushka/pythonApp1/dst_folder&quot;
  
  # only .txt files will be copied
  ext = (&quot;.txt&quot;)
  
  try:
      for src_f in os.scandir(src_folder):
          for dst_f in os.scandir(dst_folder):
              if src_f.path.endswith(ext) and os.path.basename(src_f) == os.path.basename(dst_f):
                  # copy file
                  shutil.copyfile(src_f, dst_f)
  
  finally:
    print(&quot;The 'try except' is finished&quot;)
  </code></pre>
  <p>I have searched and tried several options to ZIP, but none of them work properly, so I need your help please</p>