How to get only part of a directory name?

-1

Hello,

I'm making an application to locate a file in a directory and save it to the database, as well as save tbm to the PATH. But I need to save only the name of the directories it finds, without being the complete directory.

For example: The files are by default always in the folder C: \ FILES \ {0} \ {1} \ {2}

I need to get only the name of the folders described in {0}, {1}, {2}.

I was able to do this, but just taking the entire path:

static void BuscaRecursivaDiretorios(string caminho)
    {
        DirectoryInfo objDir = new DirectoryInfo(caminho);
        foreach (DirectoryInfo objSubDir in objDir.GetDirectories())
        {
            BuscaRecursivaDiretorios(objSubDir.FullName);
        }

        foreach (FileInfo objFile in objDir.GetFiles())
        {
            Console.WriteLine(objFile.FullName);
        }
    }
    
asked by anonymous 16.01.2018 / 19:01

1 answer

0

I broke my mind for a long time to do this, because I was trying to follow the line of reasoning of the submitted posts. But it did no good. This is where I finally got the solution.

item.Replace(@"C:\Arquivos", "");

The first parameter is the value I want to find and the second one I want to replace.

    
18.01.2018 / 15:40