Create Strings as file list...

A command in the New menu to create a Strings object containing a list of files in a given folder.

Settings

Name
the name of the resulting Strings object.
File path
the folder name, with an optional wildcard (see below) for selecting files.

Behaviour

The resulting Strings object will contain an alphabetical list of file names, without the preceding path through the folder structures. If there are no files that match the file path, the Strings object will contain no strings.

Usage

There are two ways to specify the file path.

One way is to specify a folder name only. On Unix, the file path could be /usr/people/miep/sounds or /usr/people/miep/sounds/, for instance. On Windows, C:\Users\Miep\Sounds or C:\Users\Miep\Sounds\. On Macintosh, /Users/miep/Sounds or /Users/miep/Sounds/. Any of these produce a list of all the files in the specified folder.

The other way is to specify a wildcard (a single asterisk) for the file names. To get a list of all the files whose names start with “hal” and end in “.wav”, type /usr/people/miep/sounds/hal*.wav, C:\Users\Miep\Sounds\hal*.wav, or /Users/miep/Sounds/hal*.wav.

Script usage

In a script, you can use this command to cycle through the files in a folder. For instance, to read in all the sound files in a specified folder, you could use the following script:

    folder$ = “/usr/people/miep/sounds”
    strings = Create Strings as file list: “list”, folder$ + “/*.wav”
    numberOfFiles = Get number of strings
    for ifile to numberOfFiles
       selectObject: strings
       fileName$ = Get string: ifile
       Read from file: folder$ + “/” + fileName$
    endfor

If the script has been saved to a script file, you can use file paths that are relative to the folder where you saved the script. Thus, with

    Create Strings as file list: “list”, “*.wav”

you get a list of all the .wav files that are in the same folder as the script that contains this line. And to get a list of all the .wav files in the folder Sounds that resides in the same folder as your script, you can do

    Create Strings as file list: “list”, “Sounds/*.wav”

As is usual in Praat scripting, the forward slash (“/”) in this example can be used on all platforms, including Windows. This makes your script portable across platforms.

See also

To get a list of folders instead of files, use Create Strings as folder list....

Links to this page


© ppgb 20201229