473,651 Members | 2,468 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Finding Most Recently Modified File

How can I use C# to find the most recently modified file in a folder?
As you can probably guess, I am just a beginner, so any help would be
appreciated.

Thanks!

Nov 17 '05 #1
3 6028
Mos Def (I loved "Oh no!"),

Use the DirectoryInfo class. With that, you can get all the files in
the folder through a call to the GetFiles method. This will return an array
of FileInfo instances, which you can check the LastWriteTime property of to
determine the time the file was last modified. From there you can search
the array and get the last file modified (by looping through and doing a
simple comparison).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

<mo************ ****@yahoo.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
How can I use C# to find the most recently modified file in a folder?
As you can probably guess, I am just a beginner, so any help would be
appreciated.

Thanks!

Nov 17 '05 #2
Dyl
Nicholas,

I'm always glad to meet another Mos Def fan!

I've got my code working ok right now, but there are a few errors that
won't let it compile.
DirectoryInfo Direc = new DirectoryInfo(@ "U:\xxxx\xxxx") ;

FileInfo[] FoldersArr = Direc.GetFiles( );

if (FoldersArr.Len gth > 0)
{
DateTime MostRecent = FoldersArr[1].LastWriteTime;
FileInfo RecentFolder;

foreach (FileInfo f in FoldersArr)
{
if (MostRecent.Com pareTo(f.LastWr iteTime) < 0)
{
MostRecent = f.LastWriteTime ;
RecentFolder = f;
}
}
}

MessageBox.Show (RecentFolder.T oString());
I run across an error on the line
MessageBox.Show (RecentFolder.T oString())

It says:

The type or namespace name 'RecentFolder' could not be found (are you
missing a using directive or an assembly reference?)

I guess I'm forgetting something about object-oriented programming or
maybe something easier.

Thanks for your help!

Nov 17 '05 #3
OT, but I had to post...

I get Google alerts on a very few things. One is my name, Nicholas. One
is Mos Def. This thread tripped both. Just odd, since I don't get many
for either, especially Mos Def, and to all of a sudden get one for
both...

Sorry for the interuption.
jtnt
http://mosdef.funky4u.com

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
23156
by: Sean Ross | last post by:
Hi. Recently I made a small script to do some file transferring (among other things). I wanted to monitor the progress of the file transfer, so I needed to know the size of the files I was transferring. Finding out how to get this information took some time (reading the manuals - googling did not prove worthwhile). Anyway, I did eventually figure out how to do it (there are a few ways, including os.path.getsize(filename)). My...
6
1915
by: Ajay | last post by:
hi! i am reading a file on the Web. How can i find out when it was last modified? thanks
13
15222
by: yaipa | last post by:
What would be the common sense way of finding a binary pattern in a ..bin file, say some 200 bytes, and replacing it with an updated pattern of the same length at the same offset? Also, the pattern can occur on any byte boundary in the file, so chunking through the code at 16 bytes a frame maybe a problem. The file itself isn't so large, maybe 32 kbytes is all and the need for speed is not so great, but the need for accuracy in the...
2
326
by: Steve Long | last post by:
Hey, does anybody know where VS.NET stores it's most recently used list that it displays on the Start page when you first open up VS? I would like to kick a item off of there but don't know where it's storing the list Thanks in advance. Steve
2
13193
by: Robizzle | last post by:
Sorry, I must be blind but I can't seem to find it anywhere. What function will return the time a file was created? I see filemtime(...) returns the time that file was last Modified and fileatime(...) returns the time that a file was last accessed but what about created? Tried php.net and google, nothing =(
2
1553
by: Dyl | last post by:
Hello, I'm working on trying to find the most recently modified file, but I keep coming across an error when building. Here's my code: DirectoryInfo Direc = new DirectoryInfo(@"U:\xxxx\xxxx"); FileInfo FoldersArr = Direc.GetFiles();
3
1857
by: Joe Kimbler | last post by:
I'm writing a "Hot Directory" software package that watches for an MP3 file to be uploaded to an FTP directory. When the file has completed uploading, it will be converted into a WAV file and imported into an automation system. The problem that I am having is telling if IIS (FTP) is done uploading the file and it is no longer in use. Currently, the software just checks the file time. If the time is older than 5 minutes, the software...
5
2451
by: nospam | last post by:
Hi there, I'm using VBScript to display a list of the ten most recently updated pages on my web site. Right now, the script lists the filenames and the date modified in a given directory. What I want to know is if there is any way to extract the page title and display that instead of the file name? Can I use .asp and VBscript to "delve" into the file and extract the title?
102
6763
by: hug | last post by:
www.webmaster, was suggested that this ng could be a better place.] I've updated my test server to handle if-modified-since. I've noticed that the (old copies I run of) IE and Netscape seem never to send if-modified-since. But the strange thing is that Opera sends if-modified-since but when I reply with "HTTP/1.0 304 Not Modified" it is not refreshing the screen from its cache, it is leaving the screen blank.
0
8275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8795
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8576
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6157
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5609
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4143
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2696
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1906
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1585
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.