A command in the New menu to create a Strings object containing a list of files in a given directory.
The resulting Strings object will contain an alphabetical list of file names, without the preceding path through the directory structures. If there are no files that match the file path, the Strings object will contain no strings.
There are two ways to specify the file path.
One way is to specify a directory 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 directory.
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.
In a script, you can use this command to cycle through the files in a directory. For instance, to read in all the sound files in a specified directory, you could use the following script:
directory$ = "/usr/people/miep/sounds"
strings = Create Strings as file list: "list", directory$ + "/*.wav"
numberOfFiles = Get number of strings
for ifile to numberOfFiles
fileName$ = Get string: ifile
Read from file: directory$ + "/" + fileName$
If the script has been saved to a script file, you can use file paths that are relative to the directory 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 directory as the script that contains this line. And to get a list of all the .wav files in the directory Sounds that resides in the same directory 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.
To get a list of directories instead of files, use Create Strings as directory list....
© ppgb, July 13, 2015