Skip to content
The Chat Archive
Human-written demonstration (OpenAssistant volunteers)· OpenAssistant (human-written) OpenAssistant Conversations (oasst2)

Write a python code that lists all audio files in a directory in seconds.

In OpenAssistant data, “assistant” turns were written by human volunteers as demonstrations. They are not model outputs.
  1. User

    Write a python code that lists all audio files in a directory in seconds.

  2. Assistant

    Sure, you can first list all the files then select the audio files.

    Here is how to list all the files (the runtime will depend on how many files you have):

    from os import listdir
    from os.path import isfile, join
    onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]
    

    Now you can filter onlyfiles to only keep audio files, to do that tell me which extensions you expect (such as ".mp3", ".wav", etc.)

  3. User

    Can this be applied to any extention such as a jpg, bmp, txt? Or just music?

  4. Assistant

    It can be applied to any set of files you wish as long as you know the extension. So if a text file has the somewhat more rare used extension asc, then you will not find it, if you are only looking for ".txt".