edited 1×, last 20.09.16 11:49:13 pm
Forum
Scripts
How to use io.enumdir
How to use io.enumdir
6 replies
1

Changelog
Lua functions io.enumdir (iterate over all files in a given directory) and io.isdir (check if a given path points to a directory)

EDIT:
I've found out it's only named in a changelog of CS2D. It doesn't say what it does nor how it works.
edited 2×, last 21.09.16 02:17:58 am
1
2
3
4
5
6
7
2
3
4
5
6
7
dir = "sys/lua/" if io.isdir(dir) then 	print(dir.." is a directory") 	for file in io.enumdir(dir) do 		print(dir..""..file) 	end end
edited 1×, last 21.09.16 05:09:46 am
edited 2×, last 21.09.16 05:33:48 am
Note that for this function dir must end with a forward slash.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function scanDir(dir)
	print("Scanning dir: ".. dir)
	
	for name in io.enumdir(dir) do
		if name ~= "." and name ~= ".." then
		
			if io.isdir(dir .. name) then
				--addDirQueue(dir .. name .."/")
				print(name)
			else
				--addFileQueue(dir .. name)
				print(name)
			end
			
		end
	end
end
1

Offline