sort files by date

Please support our Perl advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: May 2005
Posts: 45
Reputation: derekn is an unknown quantity at this point 
Solved Threads: 0
derekn derekn is offline Offline
Light Poster

sort files by date

 
0
  #1
Jul 7th, 2009
Could someone please help me figure out how to sort files in a directory by date? There are a lot of files to sort, thousands. All I want to do is sort by date last modified or accessed and then print that array.

Thanks,
Derek
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 898
Reputation: KevinADC has a spectacular aura about KevinADC has a spectacular aura about 
Solved Threads: 67
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Posting Shark

Re: sort files by date

 
0
  #2
Jul 7th, 2009
You need to use a file test operator -M or the stat() function to get the date and the sort() function to sort them. But I bet a Google search would find plenty of examples of code already written, so search yourself:

http://www.google.com/search?q=perl+sort+files+by+date
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 45
Reputation: derekn is an unknown quantity at this point 
Solved Threads: 0
derekn derekn is offline Offline
Light Poster

Re: sort files by date

 
-1
  #3
Jul 7th, 2009
Originally Posted by KevinADC View Post
You need to use a file test operator -M or the stat() function to get the date and the sort() function to sort them. But I bet a Google search would find plenty of examples of code already written, so search yourself:

http://www.google.com/search?q=perl+sort+files+by+date
Smart comments are so unecessary. If there were plenty of examples of code already written by searching Google, don't you think I would have used it, instead of posting on here for help? I DID search myself.

I used the -M operator and sorted that way, but it takes a very long time. Is that normal for that many files? I'd like something faster, if possible.

**Real help only, please**

Derek
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 898
Reputation: KevinADC has a spectacular aura about KevinADC has a spectacular aura about 
Solved Threads: 67
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Posting Shark

Re: sort files by date

 
0
  #4
Jul 7th, 2009
The google search found many many examples, so I assume you didn't search, and I assume you don't want anymore help from me. I'll just take my smart ass over to another thread and help people that aren't hyper sensitive.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 51
Reputation: onaclov2000 is an unknown quantity at this point 
Solved Threads: 5
onaclov2000 onaclov2000 is offline Offline
Junior Poster in Training

Re: sort files by date

 
0
  #5
Jul 7th, 2009
I'm not sure if it's fast or not, but can you do a ls-t, grep the names, then print them?
Ex.
@x = `ls -t`;

foreach $x (@x)
{
print $x;
}
$asdf = <>;


That was pretty quick with like 20 files, I don't know the throughput for 1000's of files

I post the occasional Perl tip and or whatever I can think of that might be helpful to people that I had a hard time figuring out how to do at my blog
Onaclov Nation
Last edited by onaclov2000; Jul 7th, 2009 at 2:05 pm.
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 45
Reputation: derekn is an unknown quantity at this point 
Solved Threads: 0
derekn derekn is offline Offline
Light Poster

Re: sort files by date

 
0
  #6
Jul 7th, 2009
Originally Posted by onaclov2000 View Post
I'm not sure if it's fast or not, but can you do a ls-t, grep the names, then print them?
Ex.
@x = `ls -t`;

foreach $x (@x)
{
print $x;
}
$asdf = <>;


That was pretty quick with like 20 files, I don't know the throughput for 1000's of files

I post the occasional Perl tip and or whatever I can think of that might be helpful to people that I had a hard time figuring out how to do at my blog
Onaclov Nation
appreciate the help. I'm using a windows machine...will "ls" work on windows? haven't had a chance to try it yet...but i know ls doesn't work in the command shell
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 51
Reputation: onaclov2000 is an unknown quantity at this point 
Solved Threads: 5
onaclov2000 onaclov2000 is offline Offline
Junior Poster in Training

Re: sort files by date

 
0
  #7
Jul 8th, 2009
Originally Posted by derekn View Post
appreciate the help. I'm using a windows machine...will "ls" work on windows? haven't had a chance to try it yet...but i know ls doesn't work in the command shell
I ran into that question on another topic I was discussing with a co-worker, we suspect since i have cygwin setup that might be skewing my answer,
ALTHOUGH we should be able to use the dir command,

After checking out MSDN:
MSDN

we find out:
/o [[:]SortOrder]
where:
d = By date and time, earliest first

I'm not at a windows machine at the moment, but it looks like you can replace ls -t with
dir /od

Good luck let me know how it works out,
If you want I have a few posts on Perl and some other various topics on my blog and you're welcome to check it out.
Onaclov Nation
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 695 | Replies: 6
Thread Tools Search this Thread



Tag cloud for Perl
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC