Click here to Skip to main content
15,887,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I'm trying to create a path where I would save the newly created layers, but I have a problem with how to enter the path to the folder that contains the file I'm copying but I want to rename it. It occurred to me to cut it off, but it's always a different name.

For example, the path to the file is: C:\Users\Documents\ArcGIS\Projects\test\Klady.gdb
And I would need: C:\Users\Documents\ArcGIS\Projects\test\

But if it were:C:\Users\Documents\ArcGIS\Projects\bodyTest\testovaci.gdb
so the same Substring or Remove will no work

What I have tried:

Here I choose which folder I am copying:
C#
private void hledatCestu_Click(object sender, RoutedEventArgs e)
        {
            using (var fbd = new FolderBrowserDialog())
            {
                DialogResult result = fbd.ShowDialog();

                if (result == System.Windows.Forms.DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath))
                {
                    string[] files = Directory.GetFiles(fbd.SelectedPath);
                    Application.Current.Dispatcher.Invoke(() => { cestaText.Text = fbd.SelectedPath.ToString(); });
                    

                }
            }

        }


Here is a separate copy:
<pre lang="C#">protected async void OK_Click(object sender, RoutedEventArgs e)
        {
            MapView mapView = MapView.Active;
            await QueuedTask.Run(async () =>
            {
                Application.Current.Dispatcher.Invoke(() =>
                {
                    _cesta = cestaText.Text;
                    _vysledny = vyslednySystem.Text;
                });
                if (!Directory.Exists(_cesta))
                {
                    MessageBox.Show("Zadaná cesta neexistuje.");
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        cestaText.Text=String.Empty;
                    });
                }
                else
                {
                    var novaCesta = _cesta.Remove(_cesta.Length - 9);//here's the crop, which is functional but not multifunctional
                    object[] parameterList = {novaCesta, @"ETRS"};
                    await StartATask("management.CreateFileGDB", parameterList);
...


I will be happy for any advice and help

Thank you
David
Posted
Updated 12-May-22 1:21am

1 solution

Use the Path.GetDirectoryName Method (System.IO) | Microsoft Docs[^]
It returns the full containing folder with no associated filename.
 
Share this answer
 
Comments
dejf111 12-May-22 7:29am    
This is it!!! Thank you!
OriginalGriff 12-May-22 7:53am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900