Get Full File Path Names From Folder And Write to Excel?

Hi all,

I’m trying to get the full file path names (“C:\users…”) from a folder. I then want to write each of these file names to a column in Excel. I’ve been trying this but keep getting different errors. Here is my workflow:

Variables:

Build Data Table:
image

Add Data Row Activity:
image

Hello,

Your variable named “GetFileDirectory” is a one-dimensional array of strings. You then use a For Each activity to loop through the strings in that array. So far, so good.

It looks to me like your issue would be in your “Add Data Row” activity, in the “ArrayRow” argument. There, you’ve typed “{file(1).ToString}”. However, file should already be a single string, because it represents a single file path in your file array.

When you try to index out of a string, it only gives you a single character of the string, so the expression you are currently using only gives you the 2nd character of the file path and that’s it. The expression you should be using is just “{file}”. Also, make sure the TypeArgument in your For Each activity is set to “String” so that the file variable is treated as a String.

If you do that, I believe it will solve your problem. If not, then please post what the actual error you encounter is, as that would help narrow down the issue.

Thanks

1 Like

Thanks Giannino. I adjusted the array expression on my “Add Data Row” activity to {file}. Now I’m receiving an error on my “Write Range” activity: “Write Range: The given key was not present in the dictionary.”

Any ideas? Thanks for the help!

Hello,

The screenshot shown in your original post doesn’t show any dictionary being used in your Write Range - judging from that code the error you got shouldn’t be possible. Did you make some change to it from the screenshot?

The error message in question is a result of a string key value not matching exactly the existing keys inside of a dictionary, e.g. if I have a variable named “Config” and type Config(“ExcelFilePath”).ToString, but when I added the value to the dictionary I used Config(“excelfilepath”) or Config(“Excel File Path”) or something like that, then I would get the error you described. I would also of course get the error if the key hadn’t been added to the dictionary at all.

This is why I’m also confused - I’m not using any dictionary here…everything remains the same.

image

@giannino.lusicic I just tried with write range inside of excel application scope and it worked fine. Odd that it didn’t work the original way!

Odd indeed! My only guess is that there was something off with the file path expression in your original write range since that’s the only expression I can’t fully see from the screenshots.

Either way, I’m glad you were able to solve your issue!

1 Like