How to get just a part of a directory name?

Asked

Viewed 455 times

-1

Hello,

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

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

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

I managed to do this, but just taking the whole 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);
        }
    }
  • 3

    One way would be what has already been answered in https://answall.com/q/35400/101. It may be that what helps you most is: https://answall.com/q/208381/101. You may not want to separate everything and only take one specific one as in https://en.stackoverflow.com/q/243891/101.

  • The examples were not clear to me. But anyway thank you.

1 answer

0


I broke my head for a long time to do this, because I was trying to follow the line of reasoning of the posts presented. But it was of no use. I finally got the solution.

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

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.