hello, how can i dofile all *.Lua files on a directory because im getting lazy of putting dofile and another dofile i just done 30+ dofiles lol. Avo User Offline
Am I the only one who noticed that some of replies in forum threads and comments in file archive just disappeared? (I don't want to create thread for it, therefore I posted here - some replies disappeared here, too.) edited 1×, last 02.05.13 09:49:30 am
@ Avo:
Dude we both were teleported to the past! So koool! Avo User Offline
Dr. DC Brown, let's back to the future.
To not break rules completely, @ KagamineLen: Engin33r has done some file that would help you. Search f.a. Can someone write this script like Starkkz? Admin/mod comment
what the heck were back to the past im about to copy that script that someone has made for me i just lost my internet connection so i cant copy it quick For Windows 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
function ReadDir(dir,readFolders,readFiles)
	if readFolders == nil then readFolders = true end
	if readFiles == nil then readFiles = true end
	os.execute('ls -a1 "'..dir..'" > tmp')
	local dir_files = {}
	for f in io.lines("tmp") do
		if string.find(f, "<DIR>") then
			local file_name = string.sub(f, 37)
			local file_dir = dir.."/"..file_name
			if file_name ~= "." and file_name ~= ".." then
				if readFolders then table.insert(dir_files, file_dir) end
			end
		else
			local foundPrefix = string.find(f, "-")
			local isFile = foundPrefix and foundPrefix == 3
			if isFile then
				local file_name = string.sub(f, 37)
				local file_dir = dir.."/"..file_name
				if readFiles then table.insert(dir_files, file_dir) end
			end
		end
	end
	os.execute('rm tmp')
	return dir_files
end
For Linux 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
function ReadDir(dir,readFolders,readFiles)
	if readFolders == nil then readFolders = true end
	if readFiles == nil then readFiles = true end
	os.execute('dir "'..dir..'" > tmp')
	local dir_files = {}
	for f in io.lines("tmp") do
		if string.find(f, "<DIR>") then
			local file_name = string.sub(f, 37)
			local file_dir = dir.."/"..file_name
			if file_name ~= "." and file_name ~= ".." then
				if readFolders then table.insert(dir_files, file_dir) end
			end
		else
			local foundPrefix = string.find(f, "-")
			local isFile = foundPrefix and foundPrefix == 3
			if isFile then
				local file_name = string.sub(f, 37)
				local file_dir = dir.."/"..file_name
				if readFiles then table.insert(dir_files, file_dir) end
			end
		end
	end
	os.execute('del tmp')
	return dir_files
end
Admin/mod comment
You should credit the work. /Starkkz if i remember there is written under that code how to use it
Spoiler of course i dont know how to use that function lol
1
2
3
4
5
6
7
folder_path = 'sys/my_autorun'
for k, v in pairs(ReadDir(folder_path, false, true))
	if string.sub(v, -4) == '.lua' then
		dofile(v)
	end
end
like i don't see the difference between windows and linux script lol KagamineLen has written
like i don't see the difference between windows and linux script lol
Windows use "del" and linux use "rm", that's all. Avo User Offline
Didn't Gajos mistake? First function is for Linux, the second one is for Windows. @ Avo: your right.
Edit: another thing the code didn't work i just tested it
1
2
3
4
5
6
7
8
modules = ("sys/lua/PBS Script v2.0/Modules")
--// Modules
for k, v in pairs(ReadDir(modules, false, true)) do
if string.sub(v, -4) == '.lua' then
dofile(v)
end
end
edited 5×, last 03.05.13 01:11:12 pm
I didn't have time to test the Linux function, but soon I'll improve it. I have already written stream library for Lua, check my profile. Starkkz has written
I didn't have time to test the Linux function, but soon I'll improve it. I have already written stream library for Lua, check my profile.
I'm using windows, i tried the stream on your profile it still not works
There are no console errors.
but there are popping cmd's when i start the server edited 2×, last 03.05.13 11:42:55 pm
@ KagamineLen: Did you put a slash at the end of the path? It won't work if so, you will see why.
Spoiler
The path will appear with two slashes, and it might affect the dofile function.
FlooD GAME BANNED Offline
so much fail
windows has "dir"
*nix has "ls"