Unix Programming - to read oldest 100 files from a directory till all end

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > August 2006 > to read oldest 100 files from a directory till all end





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author to read oldest 100 files from a directory till all end
shruti.dabhade@gmail.com

2006-07-22, 1:18 pm

hii
my doubt is this-
from a directory i wud like to read the files stored there.
but i want it to happen like this-
read only 100 files at a time.go on reading 100-100 till all files have
been read.
also it shud always read the oldest files first.
i.e files shud be read in the order tht they had come to the folder.

can somebody plz help me wid this.
its really urgent.

thanx in advance

-shruti.

Gordon Burditt

2006-07-22, 7:20 pm

>from a directory i wud like to read the files stored there.
>but i want it to happen like this-
>read only 100 files at a time.go on reading 100-100 till all files have
>been read.
>also it shud always read the oldest files first.
>i.e files shud be read in the order tht they had come to the folder.


Make a list of files in the directory, using opendir() and readdir().
The results will come in no particular order.

There is no guaranteed way you can tell "when a file came to the folder".
You can get close with st_mtime or st_ctime from stat() on each file.

Sort the files by time. Perhaps this is an in-memory sort with qsort().

I don't know what you mean by "read 100 files at a time". Open 100
files, read a byte from each, repeat reading the next byte from
each file until end-of-file?

Gordon L. Burditt
Bill Marcum

2006-07-23, 7:20 pm

On 22 Jul 2006 10:25:44 -0700, shruti.dabhade@gmail.com
<shruti.dabhade@gmail.com> wrote:
> hii
> my doubt is this-
> from a directory i wud like to read the files stored there.
> but i want it to happen like this-
> read only 100 files at a time.go on reading 100-100 till all files have
> been read.
> also it shud always read the oldest files first.


popen("ls -tr", "r")


--
My apologies if I sound angry. I feel like I'm talking to a void.
-- Avery Pennarun
Swarup Baran

2006-07-25, 7:48 am


Bill Marcum wrote:
> On 22 Jul 2006 10:25:44 -0700, shruti.dabhade@gmail.com
> <shruti.dabhade@gmail.com> wrote:
>
> popen("ls -tr", "r")
>
>
> --
> My apologies if I sound angry. I feel like I'm talking to a void.
> -- Avery Pennarun



Here is how you can list n oldest files

ls -lrt <directory>/<file extensions> | grep -v total | awk -F " "
'{print $9}' | head -100

this will list 100 oldest files of particular extension in a given
directory

Regards,
Swarup

You will if you can,
You won't if you can't

Chris McDonald

2006-07-25, 7:48 am

"Swarup Baran" <swarup.baran@gmail.com> writes:

>Here is how you can list n oldest files


>ls -lrt <directory>/<file extensions> | grep -v total | awk -F " "
>'{print $9}' | head -100


>this will list 100 oldest files of particular extension in a given
>directory


Or something like:

ls -F1t | grep -v '[*@/=]$' | head -100

---
Chris,
jmcgill

2006-08-11, 1:31 am

Swarup Baran wrote:

> Here is how you can list n oldest files
>
> ls -lrt <directory>/<file extensions> | grep -v total | awk -F " "
> '{print $9}' | head -100
>
> this will list 100 oldest files of particular extension in a given
> directory
>


ouch. Getting the *next*, an n*100th, files will be a neat trick from here.
Eric Sosman

2006-08-11, 1:40 pm



jmcgill wrote On 08/10/06 21:18,:
> Swarup Baran wrote:
>
>
>
>
> ouch. Getting the *next*, an n*100th, files will be a neat trick from here.


... | head -200 | tail -100

--
Eric.Sosman@sun.com

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com