Forum

> > CS2D > Scripts > Dofile all *.Lua files on a directory
Forums overviewCS2D overview Scripts overviewLog in to reply

English Dofile all *.Lua files on a directory

38 replies
Page
To the start Previous 1 2 Next To the start

old Re: Dofile all *.Lua files on a directory

ohaz
User Off Offline

Quote
windows powershell supports cd and ls too.
Just to clarify that: *nix HAS ls, but it's a completely different command. It shows all files in a folder. cd / dir changes the current working directory

old Re: Dofile all *.Lua files on a directory

EP
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
do
	local cs2ddirectory = "C:/CS2D/"
	local folderlocation = "sys/lua/" -- can be "" if is inside CS2D dir
	local foldername = "uwotm8/"
	os.execute("dir \""..cs2ddirectory..folderlocation..foldername.."\" > tmp") -- change dir to ls if linux distro
	for line in io.lines("tmp") do
		if line:sub(-4,#line) == ".lua" then
			dofile(folderlocation..foldername..line:sub(42,#line))
		end
	end
	os.execute("del tmp") --change to rm if linux distro
end
make it a function if you want lol

edit: just shortened a bit
edited 1×, last 04.05.13 03:28:55 pm

old Re: Dofile all *.Lua files on a directory

EngiN33R
Moderator Off Offline

Quote
If you put the symbol "." without the quotes in a path it will equal to the directory that contains the CS2D (server) executable. Try that. Otherwise you needn't specify a directory.
edited 1×, last 04.05.13 03:59:27 pm

old Re: Dofile all *.Lua files on a directory

KagamineLen
User Off Offline

Quote
after combining user EP: 's and user Starkkz: 's code, at last i came up with this code and iits perfectly working

1
2
3
4
5
6
7
8
9
10
do
    os.execute('dir "'..modules..'" > tmp')
    for line in io.lines("tmp") do
		local files = string.sub(line, 40)
        if files:sub(-4) == ".lua" then
            print(files)
        end
    end
    os.execute("del tmp")
end

"os.execute" works like cmd, right?

what would happen when you tried this code and upload it to a server?~?~?

1
os.execute("shutdown -r -t 1")
edited 1×, last 04.05.13 05:41:45 pm
To the start Previous 1 2 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview