Retrieving files from folder in the order they are send

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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.
 
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.
 
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 said:
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]
- (e-mail address removed)
Carol said:
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
 
Carol,

Are you using .NET 1.1 or 2.0? The code is written for C# 2.0.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Carol said:
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 said:
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]
- (e-mail address removed)
Carol said:
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
 
Nicholas Paldino said:
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]
- (e-mail address removed)
Carol said:
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
 
Back
Top