Forum

> > CS2D > Scripts > Dofile all *.Lua files on a directory
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Dofile all *.Lua files on a directory

38 Antworten
Seite
Zum Anfang Vorherige 1 2 Nächste Zum Anfang

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

ohaz
User Off Offline

Zitieren
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

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

EP
User Off Offline

Zitieren
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
1× editiert, zuletzt 04.05.13 15:28:55

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

EngiN33R
Moderator Off Offline

Zitieren
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.
1× editiert, zuletzt 04.05.13 15:59:27

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

KagamineLen
User Off Offline

Zitieren
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")
1× editiert, zuletzt 04.05.13 17:41:45
Zum Anfang Vorherige 1 2 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht