ReadDir.htm 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <html>
  2. <head>
  3. <title>Blitz3D Docs</title>
  4. <link rel=stylesheet href=../css/commands.css type=text/css>
  5. </head>
  6. <body>
  7. <h1>ReadDir (directory)</h1>
  8. <h1>Parameters</h1>
  9. <table>
  10. <tr>
  11. <td>
  12. directory = full path and name of folder/directory to open
  13. </td>
  14. </tr>
  15. </table>
  16. <h1>Description</h1>
  17. <table>
  18. <tr>
  19. <td>
  20. In file operations, you will often need to parse through a directory/folder and retrieve unknown filenames and other folders from it. This command opens a specified folder to begin these operations. The command returns a file handle which is used by the other commands to perform other services (like most file operators). You will use the NextFile$ to iterate through each entry (use FILETYPE to see if it is a file or folder). Remember, once completed, good programming practice dictates that you CloseDir the open folder. The example should help out alot.
  21. </td>
  22. </tr>
  23. </table>
  24. <h1><a href=../2d_examples/ReadDir.bb>Example</a></h1>
  25. <table>
  26. <tr>
  27. <td>
  28. ; ReadDir/NextFile$/CloseDir example <br />
  29. <br />
  30. ; Define what folder to start with ... <br />
  31. folder$="C:" <br />
  32. <br />
  33. ; Open up the directory, and assign the handle to myDir <br />
  34. myDir=ReadDir(folder$) <br />
  35. <br />
  36. ; Let's loop forever until we run out of files/folders to list! <br />
  37. Repeat <br />
  38. ; Assign the next entry in the folder to file$ <br />
  39. file$=NextFile$(myDir) <br />
  40. <br />
  41. ; If there isn't another one, let's exit this loop <br />
  42. If file$="" Then Exit <br />
  43. <br />
  44. ; Use FileType to determine if it is a folder (value 2) or a file and print results <br />
  45. If FileType(folder$+"\"+file$) = 2 Then <br />
  46. Print "Folder:" + file$ <br />
  47. Else <br />
  48. Print "File:" + file$ <br />
  49. End If <br />
  50. Forever <br />
  51. <br />
  52. ; Properly close the open folder <br />
  53. CloseDir myDir <br />
  54. <br />
  55. ; We're done! <br />
  56. Print "Done listing files!"
  57. </td>
  58. </tr>
  59. </table>
  60. <br>
  61. <a target=_top href=../index.htm>Index</a><br>
  62. <br>
  63. Click <a href=http://www.blitzbasic.co.nz/b3ddocs/command.php?name=ReadDir&ref=comments target=_blank>here</a> to view the latest version of this page online</body>
  64. </html>