reading directories

R

Robin

When you readdir will it sort the files of into the array ie:
@a = readdir (DIR);
by the file modified or by the name?

Thanks.
 
G

gnari

Robin said:
When you readdir will it sort the files of into the array ie:
@a = readdir (DIR);
by the file modified or by the name?

you should assume the order to be undefined.

gnari
 
T

Tony Curtis

When you readdir will it sort the files of into the array
ie: @a = readdir (DIR); by the file modified or by the name?

Nope, raw directory order.

hth
t
 
W

Walter Roberson

:When you readdir will it sort the files of into the array ie:
:mad:a = readdir (DIR);
:by the file modified or by the name?

No. It returns them in "directory entry" order. What order that is
depends on the operating system, the filesystem, and the OS revision.

For example, SGI's [unix] "efs" filesystem uses fixed-sized entries and
always puts a new entry into the next available slot, effectively
re-writing only a block at a time. (Thus, directories rarely shrink
for efs filesystems.} SGI's later [unix] "xfs" filesystems
uses variable-sized entries, an N-tree structure [ (2,3)-Tree I think
it is], and always re-writes the -entire- directory into the new
N-tree when it flushes to disk; under "xfs", "directory entry order"
is whatever happens to work out for the N-tree.

If you happen to be using a unix-derived system, you can probably
see the directory order by using ls -f
 
A

Anno Siegel

Robin said:
When you readdir will it sort the files of into the array ie:
@a = readdir (DIR);
by the file modified or by the name?

Neither. They are returned in no particular order, depending on how they
are found in the directory.

You want them sorted, you sort them. See "perldoc -f stat" for sorting by
anything but the name. Also, for large directories, a Schwartz transform
may be a good idea for sorting.

Anno
 
R

Robin

Once again I dunno where to start :) Where can I find documentation or does
someone have a routine to sort directories by when they were modified?

Thanks,
-Robin
 
T

Tony Curtis

Once again I dunno where to start :) Where can I find
documentation or does someone have a routine to sort
directories by when they were modified?

.... where "they" means? The directories themselves, or the
entries within the directory? How do you want to sort the
directory entries?

File::stat is probably what you are looking for if you want to
sort directories based on modification times of files within
them.

hth
t
 
T

Tad McClellan

[ Thank you for putting the subject of your article in the Subject
of your article this time.

Please do not top-post.

Have you seen the posting guidelines that are posted here frequently?
]



Robin said:
Once again I dunno where to start :)


perldoc -q sort
perldoc -f sort
perldoc -f stat
perldoc -f -X



[snip TOFU]
 
T

Tore Aursand

Once again I dunno where to start :) Where can I find documentation or
does someone have a routine to sort directories by when they were
modified?

Read the documentation:

perldoc -f sort
perldoc -f readdir
perldoc -q sort
perldoc -f stat
 
R

Robin

thanks.

--
peace,
Robin
--------------
(e-mail address removed)
Please CC a copy of your message to me.
--------------

Robin said:
Once again I dunno where to start :) Where can I find documentation or does
someone have a routine to sort directories by when they were modified?

Thanks,
-Robin
 
W

Web Surfer

[This followup was posted to comp.lang.perl.misc]
, (e-mail address removed) says...
When you readdir will it sort the files of into the array ie:
@a = readdir (DIR);
by the file modified or by the name?

Thanks.

The output from readdir() is not roted.

You can sort it by doing something like this :

@a = sort readdir (DIR);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,145
Messages
2,570,824
Members
47,371
Latest member
Brkaa

Latest Threads

Top