locked
Retrieve files from folder + script task : Error: Second path fragment must not be a drive or UNC name RRS feed

  • Question

  • Hi.

    I am trying to retrieve files from a folder using the script task functionality in SSIS.

    I have created a variable called ExcelFolder which contains the path of the files. In the script task, I have used the code as below

     // ExcelFolder contains value as D:\test\folder1\
    
     excelFolder = Dts.Variables["ExcelFolder"].Value.ToString();             
     var directory = new DirectoryInfo(excelFolder);
     FileInfo[] files = directory.GetFiles(excelFolder);

    I am getting error in the files line as - Second path fragment must not be a drive or UNC name.\r\nParameter name: path2

    How to fix this?

    Thanks

    Friday, March 27, 2020 1:15 PM

Answers

  • Hi Venkatzeus,

    You need to add a file wildcard as a second parameter.

    ...
    const String fileWildcard = "*.xslx";
    FileInfo[] files = directory.GetFiles(excelFolder, fileWildcard);

    • Marked as answer by Venkatzeus Saturday, April 4, 2020 6:05 AM
    Friday, March 27, 2020 2:01 PM

All replies

  • FileInfo[] files = directory.GetFiles(excelFolder);

    See DirectoryInfo.GetFiles Method; GetFiles expects a search pattern, not a complete file name; that's what the error message is also telling you.

    And this really not a SSIS related question, but a C# one.


    Olaf Helper

    [ Blog] [ Xing] [ MVP]

    Friday, March 27, 2020 1:58 PM
  • Hi Venkatzeus,

    You need to add a file wildcard as a second parameter.

    ...
    const String fileWildcard = "*.xslx";
    FileInfo[] files = directory.GetFiles(excelFolder, fileWildcard);

    • Marked as answer by Venkatzeus Saturday, April 4, 2020 6:05 AM
    Friday, March 27, 2020 2:01 PM
  • Hi Venkatzeus,

    The following link will be helpful:

      Second path fragment must not be a drive or UNC name

    Best Regards,

    Mona


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Monday, March 30, 2020 3:06 AM