Hello community,

I am completely new to the world of Godot and am looking forward to learning a lot of new things.
To start with, I have a very small project in mind to learn basic elements.

This one is about creating a folder structure with the click of a button.
There is a create button and a button to select the directory where the folder structure should be created.
I have already managed to created the folder structure by pressing the create button.
And when pressing the button to select the directory, the File Dialog window opens and you can select a target folder.

What I need support with is how to set the path of the File Dialog window as the creation location for the folder structure?
So that after the path has been selected via the File Dialog window, it is stored and when pressing the create button, this selected path is used to create the folder structure.

It would be nice if you could help me and give tips. 🙂

With kind regards
rktpxl

  • xyz replied to this.
  • xyz You are awsome @xyz! Thank you very much for the hint, because now it works! 😃

    And here is the code, for everyone who is new and has the same question/problem.
    Hope it will help!

    extends Node
    
    # Creates a Variable from the FileDialog Node (strg+Drag) to use it here
    @onready var file_dialog = $FileDialog
    
    
    # Name of the project-folder
    var main_project = 'My_Project'
    
    
    # Executes when the "set_project" button is pressed
    func _on_set_project_pressed():
    	# Shows the Window of the FileDialog
    	file_dialog.popup()
    	
    
    # Executes when the "create_project" button is pressed
    func _on_create_project_pressed():
    	# Creates a Variable with the current FileDialog path (selected over the window)
    	var project_path = DirAccess.open(file_dialog.current_path)
    	# Creates the projectfolder in the selected directory
    	project_path.make_dir(main_project)
    	
    
    	# Creates sub-folder in the "main_project"
    	var project_folder = file_dialog.current_path + '/' + main_project
    	var sub_dir = DirAccess.open(project_folder)
    	sub_dir.make_dir('01_folder')
    	sub_dir.make_dir('02_folder')
    	sub_dir.make_dir('03_folder')
    rktpxl changed the title to How can I store a path (File Dialog) to reuse them? .

    rktpxl FileDialog has the current_path property that contains, well... the current path 🙂

      xyz
      Hi and thank you for the hint and your feedback xyz! 🙂

      But can you also tell me or give an example how i can use this?
      I'm really a complete Beginner and have no great experiance with coding things.

      What mean String before current_path? I know what a string is, but I think I don't know how what to do with that or how to use it.

      Many thanks in advance for your help! ^^

      • xyz replied to this.

        rktpxl Hard to give a specific advice without seeing your scene structure and code you've made so far.

          xyz
          I understand and that make sence. I will make a screenshot and show the code.

          xyz
          So, here are two screenshots of my scene (2D, Script) and the code i have written:


          The Code:

          extends Node
          
          # Variabels (global)
          @onready var file_dialog = $FileDialog
          
          var path = 'C:/Users/.../Desktop/Target_Folder'
          var open_path = DirAccess.open(path)
          var project_name = 'My_Project'
          
          # Open the File-Dialog window
          func _on_btn_open_fd_pressed():
          	file_dialog.popup()
          
          # create the folder structure
          func _on_btn_create_pressed():
          	# Main folder 'New_Project'
          	open_path.make_dir(project_name)
          	
          	# Sub folder in 'New_Project'
          	var project_folder = path + '/' + project_name
          	var sub_dir = DirAccess.open(project_folder)
          	sub_dir.make_dir('01_folder')
          	sub_dir.make_dir('02_folder')
          	sub_dir.make_dir('03_folder')

          Hope this helps?! 🙂

          • xyz replied to this.

            rktpxl From your script you can access the properties of FileDialog node like this:

            $FileDialog.current_path

            Check the class reference on FileDialog node in the documentation to see what else you can do with it.

              xyz You are awsome @xyz! Thank you very much for the hint, because now it works! 😃

              And here is the code, for everyone who is new and has the same question/problem.
              Hope it will help!

              extends Node
              
              # Creates a Variable from the FileDialog Node (strg+Drag) to use it here
              @onready var file_dialog = $FileDialog
              
              
              # Name of the project-folder
              var main_project = 'My_Project'
              
              
              # Executes when the "set_project" button is pressed
              func _on_set_project_pressed():
              	# Shows the Window of the FileDialog
              	file_dialog.popup()
              	
              
              # Executes when the "create_project" button is pressed
              func _on_create_project_pressed():
              	# Creates a Variable with the current FileDialog path (selected over the window)
              	var project_path = DirAccess.open(file_dialog.current_path)
              	# Creates the projectfolder in the selected directory
              	project_path.make_dir(main_project)
              	
              
              	# Creates sub-folder in the "main_project"
              	var project_folder = file_dialog.current_path + '/' + main_project
              	var sub_dir = DirAccess.open(project_folder)
              	sub_dir.make_dir('01_folder')
              	sub_dir.make_dir('02_folder')
              	sub_dir.make_dir('03_folder')