Help Me Retrieve the Index Letters from a file name

So, for the “Switch” activity Tutorial in the “Control Flow in Studio” course, I was told to use the following within an Assign activity, FileName is the Variable, and File.Name.Substring(0, File.Name.LastIndexOf("."c)) is the argument meant to retrieve the “Short file name” - as in the file name without the file type extension at the end (eg: .pdf, or .xlsx)

The error I am getting is

Name looks as if it should be a built in kind of thing - because the tutorial doesn’t claim it as a variable at all.

Thank you for any help you can provide
(I will add the solution file here as well, so that you know what they’re attempting to teach me) Switch Solution.zip (1.2 MB)

Tag: error BC30456 Name is not a member of File

Test to remove the period between File And Name. So “FileName.Substring(…)" instead of “File.Name.…”.

Hi @jezaia.vanderwatt

Your solution is working at my end. Try to replace File variable with below syntax:

 File = New System.IO.FileInfo(Invoice)

Try this.

Regards

1 Like

At my end everything works perfectly fine…

“File” is data type “System.io.fileinfo”
It has propperty “Name” that holds the name of the file.

image

Using the “Substring” method is the retrieved the file name without extension.

Personally, I would rather use following method to get the file name wihtout extension.
FileName = path.GetFileNameWithoutExtension(File.Name)

Cheers

1 Like

Ah… I think this name property thing should fix it.

Thank you - I feel stupid now - but I am a beginner after all.

Update:
hmmm - still says “Name” is not a member of “File” with that same error code.
I will try your alternative method
Same error even with your alternative method.

Well - thank you anyway - I will learn from this even if I can’t pull it off myself (I will look at the differences btwn my version and the solution’s version to see what differences might be causing the issue).

Strange. As I said it works without change at my end :frowning:

Check the “file” variable that it is “System.io.fileinfo” data type.

image

One more thing - open the expression in advanced editor and try hover over the “file” variable, it should show you the pop-up description of the variable like in screenshot below

You could also test to rename your File variable to something else, e.g. File1. Using “File” as name might conflict with the File class.

The only reasonable explanation here, is that u declared ur File variable with the wrong type.
So your File variable doesnt reference a proper File object.
Look it up in ur variables panel. I bet thats the reson u got that error.

The only reasonable explanation here, is that u declared ur File variable with the wrong type.
So your File variable doesnt reference a proper File object.
Look it up in ur variables panel. I bet thats the reson u got that error.

No it doesnt … Variable names are handled seperatly from class names.
As long as you dont try to name your variable “if”, “else”, “true” or “false” or some other reserved keyword u are fine.

@J0ska and @nikh93

This was the 1st thing I did when I saw your original post thank you.
It definitely has this variable type.

But “FileName” variable should be “string” type

1 Like

You are correct… lets see if that fixes it.
I have another funny bug that sais “Substring is not a member of FileInfo”
Which makes me think the system is contradicting itself.(Which clearly is not the case).

Update: Making it a string type did not fix the File Name retrieving activity.
It still says “Name is not a member of File”.
At least the “Substring is not a member of FileInfo” bug went away though.

Thank you for your help - please stop if this is wasting your time. I have an alternative method that has already proven to work (you’d be in shock if you saw what my alternative method was though :sweat_smile: )

is no bug:
Substring is a method from the String class
FileInfo is not a String
FileInfo.Name will return a String, therefore the Substring method can be used for the returned Name

1 Like

I can recommend only thing: The provided sample “Switch Solution.zip” is correct. So study this example, compare with your workflow, find the difference.

And because working with UiPath you can’t avoid some .NET coding you should understand some .NET basics - what are data types, methods, propperties etc. For this you could also use “InteliSense” that is suggesting valid options in current context

Cheers

Thank you!

(I do recall saying I’d do that)

(I will look at the differences btwn my version and the solution’s version to see what differences might be causing the issue).

Ooh! I see the issue now


It is showing File as a String which is wrong… but I wouldn’t know how to fix it since this isn’t a variable, and an assign activity doesn’t have an argument type property like the Switch activity does.

But you pasted before screenshot where you declare variable with name “File_Var”, you should use this variable…

image

No. Because you did not declare variable with name “File” (like it is in the example) but with name “File_Var” it is interpreting “File” as .NET “File Class” as mentioned by @ptrobot before.

1 Like

oh - I thought I reconciled that one to be the same.
Well. what a comedy of errors.

Please have a lovely day - I’m sure you have better things to do with your time than helping me with this.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.