| | |
sort files by date
Please support our Perl advertiser: Programming Forums - DaniWeb Sister Site
![]() |
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
http://www.google.com/search?q=perl+sort+files+by+date
•
•
Join Date: May 2005
Posts: 45
Reputation:
Solved Threads: 0
•
•
•
•
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
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
•
•
Join Date: Jun 2008
Posts: 51
Reputation:
Solved Threads: 5
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
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.
•
•
Join Date: May 2005
Posts: 45
Reputation:
Solved Threads: 0
•
•
•
•
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
•
•
Join Date: Jun 2008
Posts: 51
Reputation:
Solved Threads: 5
•
•
•
•
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
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
![]() |
Similar Threads
- sort selection, arrays and i/o files (C++)
- Zip files by date (Shell Scripting)
- Sorting files on creation date (C++)
- Sort items in ListBox by 3 conditions (C++)
- Isass.exe Application Error Referenced (Viruses, Spyware and other Nasties)
- finding files for specified date (Shell Scripting)
- Search for files within certain date range (VB.NET)
- Insertion sort with files (C)
- Can't remove Trojan horse (Viruses, Spyware and other Nasties)
Other Threads in the Perl Forum
- Previous Thread: Parsing Through .bin file assistance
- Next Thread: populate perl array from database
Views: 695 | Replies: 6
| Thread Tools | Search this Thread |
Tag cloud for Perl





