viernes, 4 de octubre de 2024

serching files on the system from a list

  1. import subprocess
  2.  
  3. c=subprocess.getoutput('ls')
  4.  
  5. r=[a for a in c.split() if 'chat' in a.lower()]
  6.  
  7.  
  8. print(r)
  9. c
  10. ['chatbot.py', 'ChatGPT.pdf']
  11.  
  12.  
  13.  
  14.  
  15. looking from a list will search all mp3 and mp4 and pdf file and will return a list with sub list for each category
  16.  
  17.  
  18.  
  19. >>> [[a for a in c.split() if d.lower() in a.lower()] for d in ['mp3','mp4','pdf']]
  20. [['1.mp3', 'output.mp3', 'tts_1.mp3'], ['pp.mp4'], ['ChatGPT.pdf', 'PDF']]

No hay comentarios:

Publicar un comentario