I was refering to the Visual Studio 2008 MSDN Documentation and found that there was a mistake in the documentation titled: How to: Copy Files with a Specific Pattern to a Directory in Visual Basic which would lead to a “The given path’s format is not supported” error if followed blindly.
The code example given in the documentation was:
For Each foundFile As String In My.Computer.FileSystem.GetFiles( _
My.Computer.FileSystem.SpecialDirectories.MyDocuments, FileIO.SearchOption.SearchTopLevelOnly, “*.rtf”)
My.Computer.FileSystem.CopyFile(foundFile, “C:\testdirectory\” & foundFile)
Next
This won’t work and it would either return a PathTooLongException or NotSupportedException. The bug lies in the fact that foundFile contains the full absolute path to the file itself. Thus, passing foundfile as the second argument to CopyFile as described in the documentation will simply mean you will be copying to C:\testdirectory\C:\Documents and Settings\username\My Documents\filename.rtf, which makes no sense at all and thus the exceptions.
You just want the filename as the second argument. So this is what you should have.
My.Computer.FileSystem.CopyFile(foundFile, “C:\testdirectory\” & System.IO.Path.GetFileName(foundFile))
Leave a Reply