473,406 Members | 2,956 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Recently Modified File

Dyl
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();

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

foreach (FileInfo f in FoldersArr)
{
if (MostRecent.CompareTo(f.LastWriteTime) < 0)
{
MostRecent = f.LastWriteTime;
RecentFolder = f;
}
}
}

MessageBox.Show(RecentFolder.ToString());
Error Message: The type or namespace name 'RecentFolder' could not be
found (are you missing a using directive or an assembly reference?)

Any help would be appreciated as always. Thanks to whoever takes the
time to answer these posts.

Nov 17 '05 #1
2 1544
Dyl wrote:
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();

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

foreach (FileInfo f in FoldersArr)
{
if (MostRecent.CompareTo(f.LastWriteTime) < 0)
{
MostRecent = f.LastWriteTime;
RecentFolder = f;
}
}
}

MessageBox.Show(RecentFolder.ToString());

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


The definition of RecentFolder is nested within your if statement. As a
result, by the time you get to your MessageBox statement that variable
has gone out of scope and is no longer usable. Either move the
MessageBox inside of the if statement, or declare RecentFolder and
initialize it outside of your if block.
--
Tom Porterfield
Nov 17 '05 #2
Dyl
Thanks Tom

Nov 17 '05 #3

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

Similar topics

0
by: Carl Owenby | last post by:
Re: Microsoft Knowledge Base Article - 174942 "File Modified Outside Source Editor" Warning Message I believe I have discovered a cause of this warning in a specific situation. I encountered...
2
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...
14
by: WindAndWaves | last post by:
Hi Gurus I have been working on a rather sophisticated update procedure for FEs of my application that are spread throughout the country. Now, I recently thought: WHAT IF I identify all the...
3
by: mosdef_underground | last post by:
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!
6
by: Juggler | last post by:
Hi all I've written a program in VB.NET that allows the user to build quotes for installing shower enclosures. As part of the program, I've included a blank Access database. I've provided them...
5
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. ...
102
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...
3
by: RAMohrmann | last post by:
Greetings, I am attempting to view all files in a directory and if those files have not been modified within the last couple days I will remove them. In order to do this I need to look at the...
9
by: mazen.s.m | last post by:
I have been trying to find a way to get the Domain and UserName of the user that last modified a file. I know how to get the owner of the file via WMI or Win32, but I can't find a way to get the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.