| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <html>
- <head>
- <title>Blitz3D Docs</title>
- <link rel=stylesheet href=../css/commands.css type=text/css>
- </head>
- <body>
- <h1>ReadDir (directory)</h1>
- <h1>Parameters</h1>
- <table>
- <tr>
- <td>
- directory = full path and name of folder/directory to open
- </td>
- </tr>
- </table>
- <h1>Description</h1>
- <table>
- <tr>
- <td>
- 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.
- </td>
- </tr>
- </table>
- <h1><a href=../2d_examples/ReadDir.bb>Example</a></h1>
- <table>
- <tr>
- <td>
- ; ReadDir/NextFile$/CloseDir example
<br />
-
<br />
- ; Define what folder to start with ...
<br />
- folder$="C:"
<br />
-
<br />
- ; Open up the directory, and assign the handle to myDir
<br />
- myDir=ReadDir(folder$)
<br />
-
<br />
- ; Let's loop forever until we run out of files/folders to list!
<br />
- Repeat
<br />
- ; Assign the next entry in the folder to file$
<br />
- file$=NextFile$(myDir)
<br />
-
<br />
- ; If there isn't another one, let's exit this loop
<br />
- If file$="" Then Exit
<br />
-
<br />
- ; Use FileType to determine if it is a folder (value 2) or a file and print results
<br />
- If FileType(folder$+"\"+file$) = 2 Then
<br />
- Print "Folder:" + file$
<br />
- Else
<br />
- Print "File:" + file$
<br />
- End If
<br />
- Forever
<br />
-
<br />
- ; Properly close the open folder
<br />
- CloseDir myDir
<br />
-
<br />
- ; We're done!
<br />
- Print "Done listing files!"
- </td>
- </tr>
- </table>
- <br>
- <a target=_top href=../index.htm>Index</a><br>
- <br>
- 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>
- </html>
|