Debian Codegraph @

docs/manual/_fileNames-S-H_.html

raw symbols SCIP
1 <html><head><meta name="robots" content="index,follow"><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
2 <title>fileNames$#</title>
3 <style>
4 td { padding-left: 5pt; padding-right: 5pt; }
5 th { padding-left: 5pt; padding-right: 5pt; }
6 code { white-space: pre-wrap; }
7 dd { white-space: pre-wrap; }
8 </style>
9 </head><body bgcolor="#FFFFFF">
10
11 <table border=0 cellpadding=0 cellspacing=0><tr><td bgcolor="#CCCC00"><table border=4 cellpadding=9><tr><td align=middle bgcolor="#000000"><font face="Monaco,Courier" size=6 color="#999900"><b>
12 fileNames$#
13 </b></font></table></table>
14 <p>A function that can be used in <a href="Formulas.html">Formulas</a>, especially in <a href="Scripting.html">Scripting</a>.</p>
15 <h2>Syntax and semantics</h2>
16 <dl>
17 <dt><b><code><font size=+1>fileNames$#</font></code></b> (<i><code><font size=+1>folderNameOrPattern$</font></code></i>)
18 <dd>return the names (not the whole paths) of the files in a folder or that match a file-name pattern with up to two asterisks.</dd>
19 </dl>
20 <h2>Behaviour</h2>
21 <p>The resulting string array will contain an alphabetical list of file names (by na&#239;ve Unicode-sorting), without the preceding path through the folder structures. If there are no files that match the file path, the string array will contain 0 strings.</p>
22 <h2>Usage</h2>
23 <p>There are two ways to specify the file path.</p>
24 <p>One way is to specify a folder name only. On Unix, the file path could be <code><font size=+1>/usr/people/miep/sounds</font></code> or <code><font size=+1>/usr/people/miep/sounds/</font></code>, for instance. On Windows, <code><font size=+1>C:\Users\Miep\Sounds</font></code> or <code><font size=+1>C:\Users\Miep\Sounds\</font></code>. On Macintosh, <code><font size=+1>/Users/miep/Sounds</font></code> or <code><font size=+1>/Users/miep/Sounds/</font></code>. Any of these produce a list of all the files in the specified folder.</p>
25 <p>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 &#8220;<code><font size=+1>hal</font></code>&#8221; and end in &#8220;<code><font size=+1>.wav</font></code>&#8221;, use <code><font size=+1>/usr/people/miep/sounds/hal*.wav</font></code>, <code><font size=+1>C:\Users\Miep\Sounds\hal*.wav</font></code>, or <code><font size=+1>/Users/miep/Sounds/hal*.wav</font></code>.</p>
26 <p>You can even use <i>two</i> wildcards: <b><code><font size=+1>fileNames$#</font></code></b> (&#8220;/usr/people/miep/sounds/*al*.wav&#8221;) gives you a list of all files whose names contain &#8220;al&#8221; and end in &#8220;wav<code><font size=+1>.</font></code></p>
27 <h2>Usage</h2>
28 <p>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:</p>
29 <code> folder$ = “/usr/people/miep/sounds”<br></code>
30 <code> list$# = <b><a href="_fileNames-S-H_.html">fileNames$#</a></b>: folder$ + “/*.wav”<br></code>
31 <code> for ifile to <a href="_size_.html">size</a> (list$#)<br></code>
32 <code> <a href="Read_from_file___.html">Read from file:</a> folder$ + “/” + list$# [ifile]<br></code>
33 <code> endfor<br></code>
34 <p>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</p>
35 <code> list$# = <b><a href="_fileNames-S-H_.html">fileNames$#</a></b>: “*.wav”<br></code>
36 <p>you get a list of all the <code><font size=+1>.wav</font></code> files that are in the same folder as the script that contains this line. And to get a list of all the <code><font size=+1>.wav</font></code> files in the folder <code><font size=+1>Sounds</font></code> that resides in the same folder as your script, you can do</p>
37 <code> list$# = <b><a href="_fileNames-S-H_.html">fileNames$#</a></b>: “Sounds/*.wav”<br></code>
38 <p>As is usual in Praat scripting, the forward slash (&#8220;/&#8221;) in this example can be used on all platforms, including Windows. This makes your script portable across platforms.</p>
39 <p>Note that the above functionality can also be written four lines shorter, using built-in functions:</p>
40 <code> folder$ = “/usr/people/miep/sounds”<br></code>
41 <code> list$# = <b><a href="_fileNames-S-H_.html">fileNames$#</a></b>: folder$ + “/*.wav”<br></code>
42 <code> for ifile to <a href="_size_.html">size</a> (list$#)<br></code>
43 <code> <a href="Read_from_file___.html">Read from file:</a> folder$ + “/” + list$# [ifile]<br></code>
44 <code> endfor<br></code>
45 <h2>See also</h2>
46 <dl>
47 <dd style="position:relative;padding-left:1em;text-indent:-2em">&#8226; <a href="_folderNames-S-H_.html"><b><code><font size=+1>folderNames$#</font></code></b></a> for finding <i>folder</i> names</dd>
48 <dd style="position:relative;padding-left:1em;text-indent:-2em">&#8226; <a href="_fileNames_caseInsensitive-S-H_.html"><b><code><font size=+1>fileNames_caseInsensitive$#</font></code></b></a> for <i>case-insensitive</i> matching</dd>
49 </dl>
50 <h3>Links to this page</h3>
51 <ul>
52 <li><a href="Create_Strings_as_file_list___.html">Create Strings as file list...</a>
53 <li><a href="FAQ__Scripts.html">FAQ: Scripts</a>
54 <li><a href="Functions.html">Functions</a>
55 <li><a href="Scripting_5_7__Vectors_and_matrices.html">Scripting 5.7. Vectors and matrices</a>
56 <li><a href="Scripting_6_4__Files.html">Scripting 6.4. Files</a>
57 <li><a href="What_was_new_in_6_2_.html">What was new in 6.2?</a>
58 <li><a href="What_s_new_.html">What's new?</a>
59 </ul>
60 <hr>
61 <address>
62 <p>© Paul Boersma 2023,2025</p>
63 </address>
64 </body>
65 </html>