I have been experimenting with some Lua code to list directories and provide them to the TeX engine.
I have been using the Lua File System (lfs) module.
The first part list the current directory (code line 4) and it is printed using \, as C:\Users\Admin\...
In the second part I iterate over the directory which I am providing as a variable,
`local z="C:/test"`
This also works if I provide it as: `local z="C:\test"
The library accepts this as a valid directory. I am curious to find out how well this will work on other operating systems (I have tested on Windows) and what is the best practice in this regard.

Full MWE listing follows. (Warning it can print 100s of pages if you test on C: alone, create a small temporary directory to test).
\documentclass{tufte-book}
\usepackage[listings]{tcolorbox}
\lstloadlanguages{[LaTeX]TeX, [primitive]TeX}
\usepackage{luacode} % loads luatexbase as well
% Emphasis
%\renewcommand{\ttdefault}{cmtt} % prefer old tt font
\newcommand\emphasis[2][blue]{\lstset{emph={exec,if,then,else,do,end,while,for,print,sprint,directlua,#2},
emphstyle={\ttfamily\textcolor{#1}}}}%
\lstset{language={[LaTeX]TeX},
escapeinside={{(*@}{@*)}},
numbers=left,
gobble=0,
stepnumber=1,numbersep=5pt,
numberstyle={\footnotesize\color{gray}},%firstnumber=last,
breaklines=true,
framesep=5pt,
basicstyle=\small\ttfamily,
showstringspaces=false,
keywordstyle=\ttfamily\textcolor{blue},
stringstyle=\color{orange},
commentstyle=\color{black},
rulecolor=\color{gray!10},
breakatwhitespace=true,
showspaces=false, % shows spacing symbol
xleftmargin=0pt,
xrightmargin=5pt,
aboveskip=3pt, % compact the code looks ugly in type
belowskip=7pt, % user responsible to insert any skips
backgroundcolor=\color{gray!15}}
\begin{document}
%\begin{tcblisting}{} uncomment if you have the latest version of tcolorbox
\begin{luacode}
require "lfs"
local temp=lfs.currentdir()
tex.sprint(-2, temp)
tex.sprint("\\par")
function attrdir (path)
for file in lfs.dir(path) do
if file ~= "." and file ~= ".." then
local f = path..'/'..file
tex.sprint (-1, f.."\\par ")
local attr = lfs.attributes (f)
assert (type(attr) == "table")
if attr.mode == "directory" then
attrdir (f)
else
-- for name, value in pairs(attr) do
--tex.sprint (-2,name, value)
-- end
end
end
end
end
local z="C:/test"
attrdir (z)
\end{luacode}
%\end{tcblisting}
\end{document}

lua-lmailing list. An entry in the Lua FAQ reference tells us: "package.configis a string where the first 'character' is the directory separator; sopackage.config:sub(1,1)is either a slash or a backslash. As a general rule, try to use this when building paths." – Paulo Cereda Mar 15 '12 at 21:05lfshaspackage.config:sub(1,1)already incorporated? – Yiannis Lazarides Mar 15 '12 at 21:17lfsgets the path separator frompackage.config.:(Maybe it relies on/, since it seems to work in most of the cases (at least for both Linux and Windows). That would be my guess.package.configis a string and the first character contains the path separator. I think it would be more reliable to create a local variable, get the path separator and use it instead of hardcoding it, but/might just work fine.:)– Paulo Cereda Mar 15 '12 at 21:28