468,539 Members | 1,614 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,539 developers. It's quick & easy.

Most recent file

Lee
I have an application where I need to find the most recent file placed in a
folder. For example, my users periodically place an image file with the
format "ImageXXXX.jpg" (where XXXX is some arbitrary number) and I need to
get the latest file in the folder. Does anyone have a .NET solution to this
problem. Any help would be greatly appreciated
Thanks,
Lee

Aug 21 '06 #1
4 1711
Would you not be able to use FileSystemWatcher?

It would get hit the instant a file would be created in your folder - or
subfolder.

Miro
-New to VB.net so you may want some other opinions.

"Lee" <le**********@philips.comwrote in message
news:8C**********************************@microsof t.com...
>I have an application where I need to find the most recent file placed in a
folder. For example, my users periodically place an image file with the
format "ImageXXXX.jpg" (where XXXX is some arbitrary number) and I need to
get the latest file in the folder. Does anyone have a .NET solution to
this
problem. Any help would be greatly appreciated
Thanks,
Lee

Aug 21 '06 #2
Lee
Not really. I don't think I explained the problem very well. I have a list
of files with a *.jpg extension and I need to find the most recent file in
the list which may not be the most recent file in the folder because other
people may have put files in there without the *.jpg extension.
"Miro" wrote:
Would you not be able to use FileSystemWatcher?

It would get hit the instant a file would be created in your folder - or
subfolder.

Miro
-New to VB.net so you may want some other opinions.

"Lee" <le**********@philips.comwrote in message
news:8C**********************************@microsof t.com...
I have an application where I need to find the most recent file placed in a
folder. For example, my users periodically place an image file with the
format "ImageXXXX.jpg" (where XXXX is some arbitrary number) and I need to
get the latest file in the folder. Does anyone have a .NET solution to
this
problem. Any help would be greatly appreciated
Thanks,
Lee


Aug 21 '06 #3
You could still tie into filesystemwatcher. Just iterate the files with
that extension you seek when watcher indicates a file has changed, and look
at their properties of all files using the FileInfo class.

something like:FileInfo fFile = new FileInfo(theiteratedfilename);
DateTime fred = fFile.CreationTime.ToString()

Subtract the created date from datetime.now using timespan classes subtract
method to give you span.Seconds, and you have how long ago the file was
created.

If that figure is less than the last files figure then the current file in
the iteration is the most recent. Just repeat until all the files are
checked.

Regards

John Timney (MVP)
"Lee" <le**********@philips.comwrote in message
news:36**********************************@microsof t.com...
Not really. I don't think I explained the problem very well. I have a
list
of files with a *.jpg extension and I need to find the most recent file in
the list which may not be the most recent file in the folder because other
people may have put files in there without the *.jpg extension.
"Miro" wrote:
>Would you not be able to use FileSystemWatcher?

It would get hit the instant a file would be created in your folder - or
subfolder.

Miro
-New to VB.net so you may want some other opinions.

"Lee" <le**********@philips.comwrote in message
news:8C**********************************@microso ft.com...
>I have an application where I need to find the most recent file placed
in a
folder. For example, my users periodically place an image file with
the
format "ImageXXXX.jpg" (where XXXX is some arbitrary number) and I need
to
get the latest file in the folder. Does anyone have a .NET solution to
this
problem. Any help would be greatly appreciated
Thanks,
Lee



Aug 21 '06 #4
Lee
Thanks, John. I'll work with that.
Regards,
Lee
"John Timney (MVP)" wrote:
You could still tie into filesystemwatcher. Just iterate the files with
that extension you seek when watcher indicates a file has changed, and look
at their properties of all files using the FileInfo class.

something like:FileInfo fFile = new FileInfo(theiteratedfilename);
DateTime fred = fFile.CreationTime.ToString()

Subtract the created date from datetime.now using timespan classes subtract
method to give you span.Seconds, and you have how long ago the file was
created.

If that figure is less than the last files figure then the current file in
the iteration is the most recent. Just repeat until all the files are
checked.

Regards

John Timney (MVP)
"Lee" <le**********@philips.comwrote in message
news:36**********************************@microsof t.com...
Not really. I don't think I explained the problem very well. I have a
list
of files with a *.jpg extension and I need to find the most recent file in
the list which may not be the most recent file in the folder because other
people may have put files in there without the *.jpg extension.
"Miro" wrote:
Would you not be able to use FileSystemWatcher?

It would get hit the instant a file would be created in your folder - or
subfolder.

Miro
-New to VB.net so you may want some other opinions.

"Lee" <le**********@philips.comwrote in message
news:8C**********************************@microsof t.com...
I have an application where I need to find the most recent file placed
in a
folder. For example, my users periodically place an image file with
the
format "ImageXXXX.jpg" (where XXXX is some arbitrary number) and I need
to
get the latest file in the folder. Does anyone have a .NET solution to
this
problem. Any help would be greatly appreciated
Thanks,
Lee



Aug 22 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Nova's Taylor | last post: by
3 posts views Thread by Suresh Kumaran | last post: by
1 post views Thread by Andibevan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.