rename a file where I only know the extension.

G

Guest

Hi,

I have to be able to rename a file, where I only know the extension of the
file. Basiclly a remote system creates a file, with a random name, but a
fixed extension.

I know how move/copy a file using the code, below, but how do I do it when I
with just a known extension. I tried *.res as the fileinfo param, but it
didn't like it


Dim fi As New FileInfo("file.res")
fi.MoveTo("newfile.res")
 
J

joecool1969

Hi,

I have to be able to rename a file, where I only know the extension of the
file. Basiclly a remote system creates a file, with a random name, but a
fixed extension.

I know how move/copy a file using the code, below, but how do I do it when I
with just a known extension. I tried *.res as the fileinfo param, but it
didn't like it

Dim fi As New FileInfo("file.res")
fi.MoveTo("newfile.res")

First of all, based on your description of hoe file is created, I
asseme you are aware that at any given point in time there could any
number of .RES files in the selected folder. And further assuning you
want to move all of them then ...

You need to obtain a list of all files with the .RES extenstion. Since
you are using VB, you can use either the Dir function or the
"proper" .NET way of doing it would be with the Directory.GetFiles
method. You'll need to use the overload that accepts a pattern in
addition to a path to a path.

The elements of the string array returned are full paths to the files
that match the pattern that you can then pass to the FileInfo class.

A lot simpler than you thought it would be, eh?
 
J

joecool1969

First of all, based on your description of hoe file is created, I
asseme you are aware that at any given point in time there could any
number of .RES files in the selected folder. And further assuning you
want to move all of them then ...

You need to obtain a list of all files with the .RES extenstion. Since
you are using VB, you can use either the Dir function or the
"proper" .NET way of doing it would be with the Directory.GetFiles
method. You'll need to use the overload that accepts a pattern in
addition to a path to a path.

The elements of the string array returned are full paths to the files
that match the pattern that you can then pass to the FileInfo class.

A lot simpler than you thought it would be, eh?

Man, I must have been stoned when I posted that. I usually proof read
better than that.
 

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