Skip to content

Commit 33975d6

Browse files
authored
Update 605-file-files.markdown
1 parent 124828d commit 33975d6

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed
Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,36 @@
11
# FILES
22

3-
> FILES (wildcards)
3+
> FILES (exp)
44
5-
Returns an array with the filenames. If there are no files returns an empty array.
5+
Returns an array with the filenames. If there are no files, `FILES` returns an empty array. `exp` can contain the wildcards `*` and `?`. `exp` can include a path.
66

7-
The directory listing, if assigned to a string, will create a string array. Each filename is assigned to its own element in the string array.
8-
sample program example:
7+
### Example 1: List all files in the current directory
98

10-
~~~
9+
```
10+
FileNames = files("*.*")
1111
12-
20 a$=FILES("*.*")
13-
30 n=LEN(a$)
14-
40 FOR i = 0 to n-1
15-
50 PRINT a$(i)
16-
60 NEXT i
12+
for f in FileNames
13+
print f
14+
next
15+
```
1716

18-
~~~
17+
### Example 2: List all files matching search string
18+
19+
```
20+
FileNames = files("t?st.bas")
21+
22+
for f in FileNames
23+
print f
24+
next
25+
```
26+
27+
### Example 3: Using a path
28+
29+
```
30+
FileNames = files("/usr/bin/*") ' Linux
31+
' FileNames = files("C:\*.*") ' Windows
32+
33+
for f in FileNames
34+
print f
35+
next
36+
```

0 commit comments

Comments
 (0)