Using Python to execute a command on every file in a folder

前端 未结 6 1079
旧时难觅i
旧时难觅i 2020-12-01 01:44

I\'m trying to create a Python script that would :

  1. Look into the folder \"/input\"
  2. For each video in that folder, run a mencoder command (to transcode
6条回答
  •  没有蜡笔的小新
    2020-12-01 02:27

    To find all the filenames use os.listdir().

    Then you loop over the filenames. Like so:

    import os
    for filename in os.listdir('dirname'):
         callthecommandhere(blablahbla, filename, foo)
    

    If you prefer subprocess, use subprocess. :-)

提交回复
热议问题