Return the path value

Asked

Viewed 84 times

3

To return the value with the name of a folder in C#?

Example, if executed:

Directory.GetFiles("%PROGRAMFILES% (x86)\MyApp", "*.*", true);

And if he succeeds he returns like this:

%PROGRAMFILES% (x86)\MyApp\MyApp.exe
%PROGRAMFILES% (x86)\MyApp\MyApp.dll

And what I want is just to return in place of Myapp only \.

Ex: \MyApp.exe or \MyApp.dll, instead of the path to the complete directory.

  • Did any help you more? You need something to be improved?

2 answers

5

  • 1

    this search is related to a file copy system like an installer I am developing.

  • 1

    NOTE: Directory.Enumeratefiles not found.

  • 1

    I don’t know what this means. Are you trying to tell me that there is a mistake? Give more details.

2

using System.IO;
    // manipular de diretorios
    DirectoryInfo dirInfo = new DirectoryInfo(@"C:\Documents and Settings\etc\etc ");

    // procurar arquivos
    BuscaArquivos(dirInfo);

private void BuscaArquivos(DirectoryInfo dir)
{
     // lista arquivos do diretorio corrente
     foreach (FileInfo file in dir.GetFiles())
    {                
           // aqui no caso estou guardando o nome completo do arquivo em em controle ListBox
           // voce faz como quiser
           lbxResultado.Items.Add(file.FullName);                
    }

    // busca arquivos do proximo sub-diretorio
    foreach (DirectoryInfo subDir in dir.GetDirectories())
    {
          BuscaArquivos(subDir);
    }
}

Browser other questions tagged

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