Advertisement
Terrah

File.lua

Aug 22nd, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.77 KB | None | 0 0
  1. local FolderBit = 2 ^ (5 - 1);
  2.  
  3. --Filter should be E:/*.* or equal, func params; string path, string file, bool isfolder
  4. --FORWARDSLASHES not backslashes
  5. local function Files(filter,func)
  6.  
  7.     local file, attrib = nwn.GetFirstFile( filter );
  8.     local folders = {};
  9.  
  10.     local index = string.find(filter, "/[^/]*$");
  11.     local path = filter:sub(1,index);
  12.     local ext = filter:sub(index);
  13.  
  14.     while file do
  15.  
  16.         --Its a folder
  17.         if attrib % (FolderBit + FolderBit) >= FolderBit then
  18.  
  19.             if file~="." and file~=".." then
  20.  
  21.                 func(path,file,true);
  22.                 table.insert(folders,file);
  23.             end
  24.         else
  25.             func(path,file,false);
  26.         end
  27.  
  28.         file, attrib = nwn.GetNextFile( );
  29.     end
  30.  
  31.     for n=1,#folders do
  32.         file = path..folders[n]..ext;
  33.         Files(file,func);
  34.     end
  35. end
  36.  
  37. return Files;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement