examples.html 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  4. <head>
  5. <title>LuaFileSystem</title>
  6. <link rel="stylesheet" href="doc.css" type="text/css"/>
  7. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
  8. </head>
  9. <body>
  10. <div id="container">
  11. <div id="product">
  12. <div id="product_logo">
  13. <a href="http://keplerproject.github.io/luafilesystem">
  14. <img alt="LuaFileSystem" src="luafilesystem.png"/>
  15. </a>
  16. </div>
  17. <div id="product_name"><big><strong>LuaFileSystem</strong></big></div>
  18. <div id="product_description">File System Library for the Lua Programming Language</div>
  19. </div> <!-- id="product" -->
  20. <div id="main">
  21. <div id="navigation">
  22. <h1>LuaFileSystem</h1>
  23. <ul>
  24. <li><a href="index.html">Home</a>
  25. <ul>
  26. <li><a href="index.html#overview">Overview</a></li>
  27. <li><a href="index.html#status">Status</a></li>
  28. <li><a href="index.html#download">Download</a></li>
  29. <li><a href="index.html#history">History</a></li>
  30. <li><a href="index.html#credits">Credits</a></li>
  31. </ul>
  32. </li>
  33. <li><a href="manual.html">Manual</a>
  34. <ul>
  35. <li><a href="manual.html#introduction">Introduction</a></li>
  36. <li><a href="manual.html#building">Building</a></li>
  37. <li><a href="manual.html#installation">Installation</a></li>
  38. <li><a href="manual.html#reference">Reference</a></li>
  39. </ul>
  40. </li>
  41. <li><strong>Examples</strong></li>
  42. <li><a href="https://github.com/keplerproject/luafilesystem">Project</a>
  43. <ul>
  44. <li><a href="https://github.com/keplerproject/luafilesystem/issues">Bug Tracker</a></li>
  45. <li><a href="https://github.com/keplerproject/luafilesystem">Git</a></li>
  46. </ul>
  47. </li>
  48. <li><a href="license.html">License</a></li>
  49. </ul>
  50. </div> <!-- id="navigation" -->
  51. <div id="content">
  52. <h2><a name="example"></a>Examples</h2>
  53. <h3>Directory iterator</h3>
  54. <p>The following example iterates over a directory and recursively lists the
  55. attributes for each file inside it.</p>
  56. <pre class="example">
  57. local lfs = require"lfs"
  58. function attrdir (path)
  59. for file in lfs.dir(path) do
  60. if file ~= "." and file ~= ".." then
  61. local f = path..'/'..file
  62. print ("\t "..f)
  63. local attr = lfs.attributes (f)
  64. assert (type(attr) == "table")
  65. if attr.mode == "directory" then
  66. attrdir (f)
  67. else
  68. for name, value in pairs(attr) do
  69. print (name, value)
  70. end
  71. end
  72. end
  73. end
  74. end
  75. attrdir (".")
  76. </pre>
  77. </div> <!-- id="content" -->
  78. </div> <!-- id="main" -->
  79. <div id="about">
  80. <p><a href="http://validator.w3.org/check?uri=referer">Valid XHTML 1.0!</a></p>
  81. </div> <!-- id="about" -->
  82. </div> <!-- id="container" -->
  83. </body>
  84. </html>