title: I have an issue with my python script for merging pdf
body: <p>I tried to create a python script for merging several pdf into one single pdf.
  but sometimes the code works and sometimes it doesn't [because of that we can assume that the code doesn't work at all :( ].</p>
  <pre><code>from PyPDF2 import PdfFileMerger
  
  import os
  
  
  list_files=os.listdir(&quot;fusion/&quot;)   # we have to put all the pdf that we want to merge in this folder
  
  nom_fichier =  input(&quot;Name the merged pdf (ne pas oublier le .pdf ) &quot;)
  
  
  &quot;&quot;&quot;
  be sure that there is only pdf files in the directory
  &quot;&quot;&quot;
  pdfs = []
  
  for file in list_files:
      i = 0
  
      if file[ len (file)-4 : len(file)] == &quot;.pdf&quot;:
          pdfs.append(file)
          i+=1
  
  
  print(pdfs)
  #fusion des pdf déterminés à l'issu de l'étape précédente
  
  merger = PdfFileMerger()
  
  for pdf in pdfs:
      merger.append(pdf)
  
  merger.write(nom_fichier)
  merger.close()
  print(&quot;the pdf is ready&quot;)
  </code></pre>
  <p>we have to create a directory fusion in the current folder (where there is the script). In that directory there will be all the pdf to merge.</p>
  <p><a href="https://i.stack.imgur.com/3NEEO.png" rel="nofollow noreferrer">what the bash show me when I run the code </a></p>