UserFunction; HW2Path - HWRM/KarosGraveyard GitHub Wiki
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](/HWRM/KarosGraveyard/wiki/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](/HWRM/KarosGraveyard/wiki/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)..[:](/HWRM/KarosGraveyard/wiki/:))
count = count + 1
end
if start_of_string then
return strsub(filestring,start_of_string,strfind(filestring,[\Bin\Release](/HWRM/KarosGraveyard/wiki/\Bin\Release)))
end
end
Authors
- TamerLane
Related Pages
Comments
Page Status
Updated Formatting? Initial
Updated for HWRM? Initial