Search code examples
c#ssisio

C# get filenames using a directory


I have a path "C:\Desktop\Testing" with multiple files e.g "abc.txt";"def.txt",

I want to display path + filename as string. Code is something like this

           string path = @"C:\Desktop\Testing";
           string[] filelist = Directory.GetFiles(path);
           foreach (string file in fileList)
             {
              
              }     
           string fullPathName = path + file;

I need the fullPathName in order to create zip by addfile.CreateEntryFromFile(fullPathName, file)

Results for fullPathName should be C:\Desktop\Testing\abc.txt


Solution

  • According to docs Directory.GetFiles

    Returns the names of files (including their paths) in the specified directory.

    So I suppose that your loop could be

    foreach (string file in fileList)
    {
        addfile.CreateEntryFromFile(file, Path.GetFileName(file));
    }     
    

    Path.GetFileName will strip the path part and returns just the filename