HW2Path()
Description
Finds the path of the
Homeword2 folder. Returns nil if nothing is found.
Example
local path = HW2Path()
local filename = path..[[data\readthis.lua]]
local handle = openfile(filename,"r")
local filecontents = read(handle,"*a")
closefile(handle)
Notes
- Seems a little hard on HW2. It does a DOS command which causes a shell window to open for a second.
- It also might not work on all systems. This was tested on windows98 (dos). I don't know if the format of DOS directory outputs varies across platforms. note: tried the "path" DOS command but it doesn't return the current path for some reason
Declaration
function HW2Path()
execute("dir > dir.txt")
local handle = openfile([[dir.txt]],"r")
local filestring = read(handle,"*a")
closefile(handle)
local start_of_string
local count = 65
while not start_of_string and count < (65+26) do
start_of_string = strfind(filestring,strchar(count)..[[:\]])
count = count + 1
end
if start_of_string then
return strsub(filestring,start_of_string,strfind(filestring,[[\Bin\Release]]))
end
end
Author
Related Pages:
There are 11 comments on this page. [Display comments]