An Unhandled Exception

L

Laurence Nuttall

Doing,

Dim arrFiles() as string
Dim strWinDir as String
Dim intRet as Integer
Dim strWavFilePath as string

StrWinDir = Space(255)
intRet = GetWindowsDirectory(StrWinDir, Len(StrWinDir))

If intRet > 0 Then
arrFiles = system.IO.Directory.GetFiles (strWinDir &
"\media\","*.wav")

End IF

'-------------------------------------------------------------

I get

An unhandled exception of type 'System.IO.PathtoLongException'
occured in mscorlib.dll

Additionl information. the path is too long after being fully
qualified. Make sure path is less than 260 characters.

'---------------------------------------------------------------

The exception occurs on the getfiles statement.
The path is less than 260 characters.

Any help would be appreciated.

Laurence Nuttall
Programmer Analyst III
UCLA - Division of Continuing Education
 
C

CJ Taylor

Laurence Nuttall said:
Doing,

Dim arrFiles() as string
Dim strWinDir as String
Dim intRet as Integer
Dim strWavFilePath as string

StrWinDir = Space(255)
intRet = GetWindowsDirectory(StrWinDir, Len(StrWinDir))
try trimming your strWinDir

I know you need the Space(255) for the buffer into unmanaged, but maybe
adding a .Trim() after all is said and done would help.

-CJ
 
H

Herfried K. Wagner [MVP]

* Laurence Nuttall said:
Doing,

Dim arrFiles() as string
Dim strWinDir as String
Dim intRet as Integer
Dim strWavFilePath as string

StrWinDir = Space(255)
intRet = GetWindowsDirectory(StrWinDir, Len(StrWinDir))

If intRet > 0 Then
arrFiles = system.IO.Directory.GetFiles (strWinDir &
"\media\","*.wav")

Cut off the content of 'strWinDir' ('intRet' will contain the length of
the windows directory's path) using 'Left'.
 
L

Laurence Nuttall

I can't find the left in vb.net, so
I used the trim

arrFiles = system.IO.Directory.GetFiles (strWinDir.Trim & "\media\","*.wav")

This still gets me the exception.

If I remove the "*.wav" and substitute ""
no exception occurs, but the arrfiles array is empty.

Larry
 
H

Herfried K. Wagner [MVP]

* Laurence Nuttall said:
I can't find the left in vb.net, so
I used the trim

'Trim' won't work here too. Use something like
'Strings.Left(strWinDir, intRet) & ...'.
 
L

Laurence Nuttall

If I put a literal "C:\Windows"
in the get files statement it works.

example:

arrFiles = system.IO.Directory.GetFiles ("C:\Windows" &
"\media\","*.wav")


but it doesn't like it if the first parameter is a variable
string.

Larry
 
H

Herfried K. Wagner [MVP]

* Laurence Nuttall said:
The (Strings.Left(strWinDir, intRet)
worked.

What is Strings.left ?

It takes the left part of a string (the 1st 'intRet' number of
characters).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top