From e65838f2d0fde14e85ae7cc664da403376127663 Mon Sep 17 00:00:00 2001 From: Alexander Holland Date: Sun, 14 Feb 2016 20:31:55 +0100 Subject: [PATCH] some doc for directory --- doc/base/classes.xml | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/doc/base/classes.xml b/doc/base/classes.xml index 0c7bbba85e1..f6b9b9f4461 100644 --- a/doc/base/classes.xml +++ b/doc/base/classes.xml @@ -9580,8 +9580,25 @@ This approximation makes straight segments between each point, then subdivides t + Directory type. - + Directory type. Is used to manage directories and their content (not restricted to the project folder). + +How to iterate through the files of a directory example: + +func dir(path): + var d = Directory.new() + if d.open( path )==0: + d.list_dir_begin() + var file_name = d.get_next() + while(file_name!=""): + if d.current_is_dir(): + print("Is directory: " + file_name) + else: + print("Is File:" + file_name) + file_name = d.get_next() + else: + print("Some open Error, maybe directory not found?") @@ -9590,28 +9607,34 @@ This approximation makes straight segments between each point, then subdivides t +Opens a directory to work with. Needs a path, example "res://folder" +Loads all file names of the current directory (prepares the get_next() function). +Is used to iterate through the files of the current directory. Returns the name(no path) of the current file/directory, it also contains "." and ".." . +Returns an empty String "" at the end of the list. +Returns true if the current file you are looking at with get_next() is a directory or "." or ".." otherwise false. +Run this to empty the list of remaining files in get_next(). You can use it to end the iteration, as soon as your goal is reached. @@ -9634,12 +9657,14 @@ This approximation makes straight segments between each point, then subdivides t +Needs a path or name to the next directory. When the target directory is in the current directory you can use "newfolder" otherwise you need the full path "res://currentfolder/newfolder" +Returns a path to the current directory, example: "res://folder" @@ -9672,6 +9697,7 @@ This approximation makes straight segments between each point, then subdivides t +Returns true if directory exists otherwise false. Needs a path, example: "res://folder"