Rashar

Hello,

I have the following code:

Dim RETURN_FILE_PATH As String

RETURN_FILE_PATH = Directory.GetFiles("C:\Temp\", "*ABC*")

The line Directory.GetFiles("C:\Temp\", "*ABC*") is giving me an error of "Value of type '1-dimensional arrary of String' cannot be converted to 'String' error....

If I do this, RETURN_FILE_PATH = Directory.GetFiles("C:\Temp\", "*ABC*").ToString and run the code, the value of RETURN_FILE_PATH is System.String[].

I could declare RETURN_FILE_PATH as Dim RETURN_FILE_PATH() and then I would get the file that I am looking for, but I need the file name to be passed as a string variable as such, C:\Temp\ABC123.txt...

Any assistance is greatly appreciated.



Re: Visual Basic Express Edition Assistance needed with Value of type '1-dimensional arrary of String' cannot be converted to 'String' error....

TilakGopi

Hi Rashar,

Directory.GetFiles() function will return an array of strings ,not a single string.Just check.

So you have to modify your code to declare a string array variable to hold the returned array from Directory.GetFiles() function as follows

Dim RETURN_FILE_PATHS As String()

RETURN_FILE_PATHS = Directory.GetFiles("C:\Temp\", "*ABC*")

Thanks,

Ch.T.Gopi Kumar.






Re: Visual Basic Express Edition Assistance needed with Value of type '1-dimensional arrary of String' cannot be converted to 'String' error....

Rashar

Hello Ch.T.Gopi Kumar

Now how do I get the value of RETURN_FILE_PATHS and pass it to a single String Variable... Is that possible

So I when I look in RETURN_FILE_PATHS, I see C:\Temp\ABC123.txt... I need that passed to a single STRING...

Thanks for your help.





Re: Visual Basic Express Edition Assistance needed with Value of type '1-dimensional arrary of String' cannot be converted to 'String' error....

Rashar

Ahh, this seems to work...

Dim RETURN_FILE_PATHS As String()

RETURN_FILE_PATHS = Directory.GetFiles("C:\Temp\", "*ABC*")

Dim showStringName As String

showStringName = RETURN_FILE_PATHS.GetValue(0)

Again, Thanks for your help.





Re: Visual Basic Express Edition Assistance needed with Value of type '1-dimensional arrary of String' cannot be converted to 'String' error....

TilakGopi

Welcome Rashar

Thanks & Regards,

Ch.T.Gopi Kumar.






Re: Visual Basic Express Edition Assistance needed with Value of type '1-dimensional arrary of String' cannot be converted to 'String' error....

Chris Dunaway

No need to use the GetValue method. You can just use:

showStringName = RETURN_FILE_PATHS(0)

Also, keep in mind that RETURN_FILE_PATHS is an array so there could be more than one string available that matches your criteria.

Chris