@@ -91,34 +91,73 @@ because it makes sure that the files are removed on exit.
9191In addition, ` os.tmpname() ` under windows often returns filenames
9292for which the user has no permission to write.
9393
94-
95-
96-
9794<a name =" paths.dirs.dok " />
9895## Directory functions ##
9996
10097The following functions can be used
10198to examine directory contents or manipulate directories.
10299
103-
104100<a name =" paths.dir " />
105101### paths.dir(dname) ###
106102
107- Return a table containing the files in directory ` dname ` .
108- This function return ` nil ` if the specified directory
109- does not exists .
103+ Return a table containing the files and directories in directory ` dname ` .
104+ This function return ` nil ` if the specified directory does not exists.
105+ For linux, this includes the ` . ` and ` .. ` directories .
110106
111107<a name =" paths.files " />
112- ### paths.files(dname) ###
108+ ### paths.files(dname [ , include] ) ###
109+
110+ Returns an iterator over the files and directories located in directory ` dname ` .
111+ For linux, this includes the ` . ` and ` .. ` directories.
112+ This can be used in * __ for__ * expression as shown below:
113+
114+ ``` lua
115+ for f in paths .files (" ." ) do
116+ print (f )
117+ end
118+ ```
119+
120+ Optional argument ` include ` is either a function or a string used to
121+ determine which files are to be included. The function takes the filename
122+ as argument and should return true if the file is to be included.
123+ When a string is provided, the following function is used :
124+
125+ ``` lua
126+ function (file )
127+ return file :find (f )
128+ end
129+ ```
130+
131+ Files and directories of sub-folders aren't included.
132+
133+ <a name =" paths.iterdirs " />
134+ ### paths.iterdirs(dname) ###
113135
114- Returns an iterator over the files located in directory ` dname ` .
136+ Returns an iterator over the directories located in directory ` dname ` .
115137This can be used in * __ for__ * expression as shown below:
138+
139+ ``` lua
140+ for dir in paths .iterdirs (" ." ) do
141+ print (dir )
142+ end
116143```
117- for f in paths.files(".") do
118- print(f)
119- end
144+
145+ Directories of sub-folders, and the ` . ` and ` .. ` folders aren't included.
146+
147+ <a name =" paths.iterdirs " />
148+ ### paths.iterfiles(dname) ###
149+
150+ Returns an iterator over the files (non-directories) located in directory ` dname ` .
151+ This can be used in * __ for__ * expression as shown below:
152+
153+ ``` lua
154+ for file in paths .iterfiles (" ." ) do
155+ print (file )
156+ end
120157```
121158
159+ Files of sub-folders, and the ` . ` and ` .. ` folders aren't included.
160+
122161<a name =" paths.mkdir " />
123162### paths.mkdir(s) ###
124163
0 commit comments