Pass NSOpenPanel Directory URL to FileManager?

Brand new to swift and generally limited programming experience. Building a simple proof-of-concept app. Have UI mostly built now trying to pass data between button functions in the UI.

Two buttons are for selecting source and target directories (they use NSOpenPanel to select connected drives), and a third to begin a directory copy via FileManager (unless there's a better way).

What I am unclear on is if I have to set up a variable for each NSOpenPanel items to store their selected URL locations, and then more generally, how to pass the stored paths to the other UI widget so that the directory copy operation begins as intended.

I also believe I need to set up a state type somewhere above where this code sits in the document, but not sure if that state can apply to all three buttons or how that works. Still working my way through various tutorials. Sorry for the nooB question but could not find anything like this on StackOverflow or similar sources. Found random things on NSOpenPanel and FileManager but not both used together.

Here is the beginnings / where I got slowed down.

Button("Source Folder") {

             let panel = NSOpenPanel()
             panel.canChooseDirectories = true
             panel.canChooseFiles = false
             panel.allowsMultipleSelection = false
             panel.isAccessoryViewDisclosed = false
             panel.runModal()
                    }

Button("Target Drive") {
             let panel = NSOpenPanel()
             panel.canChooseDirectories = true
             panel.canChooseFiles = false
             panel.allowsMultipleSelection = false
             panel.isAccessoryViewDisclosed = false

             if panel.runModal() == .OK {}
                    }
                    
Button("Begin Transfer") {
             func copyItem(atPath: String, toPath: String)
                    }

ignore

Doesn't appear I can edit original but possibly this gets me closer. The declared variables don't seem to be available to the transfer button when reviewing code error msg.

                    Button("Source Folder") {

                        let panel = NSOpenPanel()
                        panel.runModal()
                        panel.canChooseDirectories = true
                        panel.canChooseFiles = false
                        panel.allowsMultipleSelection = false
                        panel.isAccessoryViewDisclosed = false
                        var chosenSource = URL(string: <#T##String#>).self
                    }

                    Button("Target Drive") {
                        let panel = NSOpenPanel()
                        panel.runModal()
                        panel.canChooseDirectories = true
                        panel.canChooseFiles = false
                        panel.allowsMultipleSelection = false
                        panel.isAccessoryViewDisclosed = false
                        var chosenTarget = URL(string: <#T##String#>).self
                    }
                    Button("Begin Transfer") {
                        func copyItem(atPath: chosenSource, toPath: chosenTarget)
                    }

Ignore second attempt, removed some items originally copied in from another example I doubt now were relevant. I think now I'm actually closer but still not 100% sure of the proper way to set the state at the beginning, whether I should use a private variable or not (many examples seem to use them but without explaining why - not sure if that means within the view only or something else.)

Still need help if someone can provide an understanding of what's missing. Left the transfer button function out this time; I think it's going to require the File Manager's copyItem method, and that this method would also use the variables (?) but open to correction and suggestion here as I'm new to all this.

struct ContentView: View {

    @Binding var urlS: URL
    @Binding var urlT: URL

    var body: some View {

        GeometryReader { geometry in

            VStack(alignment: .leading, spacing: 10.0) {

                Button ("Select Source") {

                    let panel = NSOpenPanel()
                        panel.canChooseDirectories = true
                        panel.canChooseFiles = false
                        panel.allowsMultipleSelection = false
                        panel.isAccessoryViewDisclosed = false
                        panel.directoryURL = self.urlS
                }

                        Button ("Select Target") {

                    let panel = NSOpenPanel()
                        panel.canChooseDirectories = true
                        panel.canChooseFiles = false
                        panel.allowsMultipleSelection = false
                        panel.isAccessoryViewDisclosed = false
                            panel.directoryURL = self.urlT
                    }
                    .padding(.top)

                    Button("Begin Transfer")    {

                    }
Pass NSOpenPanel Directory URL to FileManager?
 
 
Q