Federico Pessina Federico Pessina - 2 months ago 6x
Vb.net Question

VB.net FileSystem.rename - old path knowing only a substring

How can I rename a file that I don't know the full name, but I only know that it begin with a base string?
I must rename a file in a folder, that begins with a default string and then has extra unknow chars. I'm sure in that folder will be only one file beginning with that string.
It would be something like searching "string*.txt" and rename it with "string.txt", but FileSystem.rename doesn't accept oldPath with "*" as argument.

Dim _files as String() = IO.Directory.GetFiles("c:\temp\", "string*.txt")
IO.File.Move(_files(0), "c:\temp\newfilename.txt")

Still needs some checking if file found, etc. but this should work