edited 1×, last 21.09.16 01:49:13 am
Forum
CS2D Scripts How to use io.enumdirHow to use io.enumdir
6 replies 1
Counter-Strike 2D 1.0.0.2 has written
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)
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 04: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 07:09:46 am
edited 2×, last 21.09.16 07: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