943,704 Members | Top Members by Rank

Ad:
  • Perl Discussion Thread
  • Unsolved
  • Views: 1623
  • Perl RSS
Jul 7th, 2009
0

sort files by date

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
derekn is offline Offline
45 posts
since May 2005
Jul 7th, 2009
0

Re: sort files by date

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
Reputation Points: 246
Solved Threads: 67
Practically a Posting Shark
KevinADC is offline Offline
898 posts
since Mar 2006
Jul 7th, 2009
-1

Re: sort files by date

Click to Expand / Collapse  Quote originally posted by KevinADC ...
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
Reputation Points: 10
Solved Threads: 0
Light Poster
derekn is offline Offline
45 posts
since May 2005
Jul 7th, 2009
0

Re: sort files by date

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.
Reputation Points: 246
Solved Threads: 67
Practically a Posting Shark
KevinADC is offline Offline
898 posts
since Mar 2006
Jul 7th, 2009
0

Re: sort files by date

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.
Reputation Points: 11
Solved Threads: 5
Junior Poster in Training
onaclov2000 is offline Offline
57 posts
since Jun 2008
Jul 7th, 2009
0

Re: sort files by date

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
Reputation Points: 10
Solved Threads: 0
Light Poster
derekn is offline Offline
45 posts
since May 2005
Jul 8th, 2009
0

Re: sort files by date

Click to Expand / Collapse  Quote originally posted by derekn ...
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
Reputation Points: 11
Solved Threads: 5
Junior Poster in Training
onaclov2000 is offline Offline
57 posts
since Jun 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Perl Forum Timeline: Parsing Through .bin file assistance
Next Thread in Perl Forum Timeline: populate perl array from database





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC