Just a quick request for an easy way to access files/folders on the Hard Drive.
I know that you already have some accessors, as I have seen
- Code: Select all
sky.getDir_Models()
Basically, I would like:
1) a way to access a directory in the final .exe directory (my own, or the "Script" directory)
2) a way to get all files in a specified directory that contain a specific suffix (such as .lua)
Thanks
Shando
EDIT: I think I've found a way to handle 2) above:
- Code: Select all
function get_files ( path, prepend_path_to_filenames )
if path:sub(-1) ~= '\\' then
path = path .. '\\';
end
local pipe = io.popen ( 'dir /b/a-d "' .. path .. '*.*" 2> nul' );
local output = pipe:read'*a';
pipe:close();
-- If your file names contain national characters
-- output = convert_OEM_to_ANSI(output)
local files = { };
for filename in output:gmatch'[^\r\n]+' do
if prepend_path_to_filenames then
filename = path .. filename;
end
-- ONLY SAVE ".cha" FILES
if ( string.sub ( filename, -4, -1 ) == ".cha" ) then
table.insert ( files, filename );
end
end
return files;
end
To use, you need something like:
- Code: Select all
-- need to change this next line depending on how we access folders in Skyline:
local array_of_files = get_files ( 'D:\\Aurasoft\\SkylineSDK', false )
for _, fn in ipairs ( array_of_files ) do
sky.lprint ( fn );
end
I found this on Stack Overflow (http://stackoverflow.com/questions/13665333/extracting-file-data-with-lua - in a response by Egor Skriptunoff), just not sure if it will work in a final game??