Heya Peeps. Hope someone can help me out ..
im wanting a function to return all file names in a specified directory..
something like this:-
Function ReadFiles()
directory = "/files"
filename = "/r/n"
number = count files // count the number of files in ' directory '
Loop // loop 1 to number
get next filename
filename = fileName.."/r/n"
end // end loop
return FileName , number
end // end function
Thanks in Advance ??????Hawk??????
function CountFiles(sDirectory)
local sFileName = tmpname ();
system("dir /b /a-d \""..sDirectory.."\" | find /c /v \"\" > \""..sFileName.."\"");
local hFile = openfile (sFileName, "r");
local iCount = read(hFile, "*n");
closefile(sFileName);
remove(sFileName);
end
Nothing to test on here. Hope it works, or you understand what I was going for.
Hrm, actually looks like you want a listing of files?
-NotRabidWombat
yes m8 . it is a listing of files that im after..
thx anyway
Alrighty, in that case.
function ReadFiles(sDirectory)
local sFileName = tmpname ();
local sLine = nil;
system("dir /b /a-d \""..sDirectory.."\" > \""..sFileName.."\"");
local hFile = openfile (sFileName, "r");
sLine = read(hFile, "*l");
while ( sLine )
-- sLine will be the file name in sDirectory
sLine = read(hFile, "*l");
end
closefile(sFileName);
remove(sFileName);
end
-NotRabidWombat
not having any joy with that function m8 :-(
Sorry. Right now I'm using the Wombot interpreter to check syntax ;-)
I'll be back home in an hour at which point I can debug.
-NotRabidWombat
hi m8 thx
i appreciate your help .. theres no rush as ive closed my script boxes down for the evening..
but i would appreciate it if you could come up with something that followed this pattern returning the info required..
Function ReadFiles()
directory = "/files"
filename = "/r/n"
number = count files // count the number of files in ' directory '
Loop // loop 1 to number
get next filename
filename = fileName.."/r/n"
end // end loop
return FileName , number
end // end function
cheers ??????Hawk??????
i bet system is c++.
changed it 2 execute and added a do.
function ReadFiles(sDirectory)
local sFileName = tmpname ();
local sLine = nil;
execute("dir /b /a-d \""..sDirectory.."\" > \""..sFileName.."\"");
local hFile = openfile (sFileName, "r");
sLine = read(hFile, "*l");
while ( sLine ) do
-- sLine will be the file name in sDirectory
sLine = read(hFile, "*l");
end
closefile(sFileName);
remove(sFileName);
end
plop
Heh! :D It has been a while since I've used lua.
Yes system is c/c++.
-NotRabidWombat
hi guys .. thx for your help .
the function works but i get this error:-
Syntax error: bad argument #1 to `closefile' (invalid file handle)
stack traceback:
and the tmp.$$$ file is left in the scripts directory.
it makes a new tmp2.$$$ / tmp3.$$$ and so on every time its executed.