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 not files that match path, the Strings object will contain no strings.
There are two ways to specify the path.
One way is to specify a directory name only. On Unix, you could type /usr/people/miep/sounds or /usr/people/miep/sounds/, for instance. On Windows, C:\Document and Settings\Miep\Sounds or C:\Document and Settings\Miep\Sounds\. On Macintosh, /Users/miep/Sounds or /Users/miep/Sounds/. Any of these return 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:\Document and Settings\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"
Create Strings as file list... list 'directory$'/*.wav
numberOfFiles = Get number of strings
for ifile to numberOfFiles
select Strings list
fileName$ = Get string... ifile
Read from file... 'directory$'/'fileName$'
If the script has been saved to a script file, you can use 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, September 19, 2006