471,337 Members | 939 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Retrieving files from folder in the order they are send

Hi,
I am in a problem.
I am sending files to a particular folder one after the another.
Than obviosly there create time is different.
Now suppose if there are 50 files and i want to retrive the files in the
order they are sent i.e. file with first create time(First in First Out).
Is it possible.
I couldn't find any such property of sorting.
Please send any link or line of code.

Answer will be appreciated

Thanking U,
Carol
Dec 16 '05 #1
5 1659
Carol,

Suppose you have an array of FileInfo instances which you need sorted,
you could do this:

// The file info array, assume it is populated.
FileInfo[] fileInfo;

Array.Sort(fileInfo,
delegate(FileInfo x, FileInfo y)
{
// If the create time on x is greater than y, then return 1, if it
is equal, then return 0, otherwise, return -1.
if (x.CreationTimeUtc == y.CreationTimeUtc)
{
// Return 0.
return 0;
}
else
{
// Check to see if x > y.
if (x.CreationTimeUtc > y.CreationTimeUtc)
{
// Return 1.
return 1;
}
else
{
// y > x.
return -1;
}
}
});

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Carol" <Ca***@discussions.microsoft.com> wrote in message
news:6E**********************************@microsof t.com...
Hi,
I am in a problem.
I am sending files to a particular folder one after the another.
Than obviosly there create time is different.
Now suppose if there are 50 files and i want to retrive the files in the
order they are sent i.e. file with first create time(First in First Out).
Is it possible.
I couldn't find any such property of sorting.
Please send any link or line of code.

Answer will be appreciated

Thanking U,
Carol

Dec 16 '05 #2
I don't think there is a way to actually retrieve the list of files in a
sorted order.
I would say just get the list in whatever order it gives them to you, then
loop through each one and create a new SortedList, where the key is the
creation date (or modified, whatever you need), and the value is the
filename/path.

--
Adam Clauss

"Carol" <Ca***@discussions.microsoft.com> wrote in message
news:6E**********************************@microsof t.com...
Hi,
I am in a problem.
I am sending files to a particular folder one after the another.
Than obviosly there create time is different.
Now suppose if there are 50 files and i want to retrive the files in the
order they are sent i.e. file with first create time(First in First Out).
Is it possible.
I couldn't find any such property of sorting.
Please send any link or line of code.

Answer will be appreciated

Thanking U,
Carol

Dec 16 '05 #3
Hi Nicholos,
Thanks for your reply
Can u plaease clarify your code.
I have copy pated buts its not working.
Can u please resend it.

"Nicholas Paldino [.NET/C# MVP]" wrote:
Carol,

Suppose you have an array of FileInfo instances which you need sorted,
you could do this:

// The file info array, assume it is populated.
FileInfo[] fileInfo;

Array.Sort(fileInfo,
delegate(FileInfo x, FileInfo y)
{
// If the create time on x is greater than y, then return 1, if it
is equal, then return 0, otherwise, return -1.
if (x.CreationTimeUtc == y.CreationTimeUtc)
{
// Return 0.
return 0;
}
else
{
// Check to see if x > y.
if (x.CreationTimeUtc > y.CreationTimeUtc)
{
// Return 1.
return 1;
}
else
{
// y > x.
return -1;
}
}
});

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Carol" <Ca***@discussions.microsoft.com> wrote in message
news:6E**********************************@microsof t.com...
Hi,
I am in a problem.
I am sending files to a particular folder one after the another.
Than obviosly there create time is different.
Now suppose if there are 50 files and i want to retrive the files in the
order they are sent i.e. file with first create time(First in First Out).
Is it possible.
I couldn't find any such property of sorting.
Please send any link or line of code.

Answer will be appreciated

Thanking U,
Carol


Dec 16 '05 #4
Carol,

Are you using .NET 1.1 or 2.0? The code is written for C# 2.0.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Carol" <Ca***@discussions.microsoft.com> wrote in message
news:49**********************************@microsof t.com...
Hi Nicholos,
Thanks for your reply
Can u plaease clarify your code.
I have copy pated buts its not working.
Can u please resend it.

"Nicholas Paldino [.NET/C# MVP]" wrote:
Carol,

Suppose you have an array of FileInfo instances which you need
sorted,
you could do this:

// The file info array, assume it is populated.
FileInfo[] fileInfo;

Array.Sort(fileInfo,
delegate(FileInfo x, FileInfo y)
{
// If the create time on x is greater than y, then return 1, if
it
is equal, then return 0, otherwise, return -1.
if (x.CreationTimeUtc == y.CreationTimeUtc)
{
// Return 0.
return 0;
}
else
{
// Check to see if x > y.
if (x.CreationTimeUtc > y.CreationTimeUtc)
{
// Return 1.
return 1;
}
else
{
// y > x.
return -1;
}
}
});

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Carol" <Ca***@discussions.microsoft.com> wrote in message
news:6E**********************************@microsof t.com...
> Hi,
> I am in a problem.
> I am sending files to a particular folder one after the another.
> Than obviosly there create time is different.
> Now suppose if there are 50 files and i want to retrive the files in
> the
> order they are sent i.e. file with first create time(First in First
> Out).
> Is it possible.
> I couldn't find any such property of sorting.
> Please send any link or line of code.
>
> Answer will be appreciated
>
> Thanking U,
> Carol


Dec 16 '05 #5
"Nicholas Paldino [.NET/C# MVP]" wrote:
Carol,

Suppose you have an array of FileInfo instances which you need sorted,
you could do this:

// The file info array, assume it is populated.
FileInfo[] fileInfo;

Array.Sort(fileInfo,
delegate(FileInfo x, FileInfo y)
{
// If the create time on x is greater than y, then return 1, if it
is equal, then return 0, otherwise, return -1.
if (x.CreationTimeUtc == y.CreationTimeUtc)
{
// Return 0.
return 0;
}
else
{
// Check to see if x > y.
if (x.CreationTimeUtc > y.CreationTimeUtc)
{
// Return 1.
return 1;
}
else
{
// y > x.
return -1;
}
}
});

or simply x.CreationTimeUtc.CompareTo( y.CreationTimeUtc )
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Carol" <Ca***@discussions.microsoft.com> wrote in message
news:6E**********************************@microsof t.com...
Hi,
I am in a problem.
I am sending files to a particular folder one after the another.
Than obviosly there create time is different.
Now suppose if there are 50 files and i want to retrive the files in the
order they are sent i.e. file with first create time(First in First Out).
Is it possible.
I couldn't find any such property of sorting.
Please send any link or line of code.

Answer will be appreciated

Thanking U,
Carol


Dec 16 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Dave Hopper | last post: by
3 posts views Thread by Brian Farnhill (MCP VB.NET) | last post: by
4 posts views Thread by Yves | last post: by
4 posts views Thread by johnb41 | last post: by
7 posts views Thread by jonathandrott | last post: by
4 posts views Thread by Joey | last post: by

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.