|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
| View Poll Results: | |||
| | 0% | ||
| Voters: 0. You may not vote on this poll | |||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Sorting Dir above files
Using apache 1.3x , win98 beta 3001, perl 5.6.x
Required : trying to sort alphabetically Dirs = first , Files =second. Code Fragment : $bob="c:\\windows"; opendir(SEARCH,"$bob") || die " Cannot open $bob : $! "; @all=sort{lc $a cmp lc $b} grep(!/^\.+$/,readdir(DIR)); closedir(SEARCH); foreach $name(@all){ print " $names\n"; } Trouble : This code works but my brain is looking for dir's above files. I suppose I am looking for a new sort fragment or ??? ![]()
__________________
Thanks Foot in Mouth ver 1.2.5 Onion |
|
#2
|
|||
|
|||
|
I'm not sure exactly what your're trying to do?
Are you trying to grab all files and dirs in a specific directory and then sort them into dirs(alphabetically) and then files(alphabetically)? If so, I beleive you can acomplish what you are trying to do much easier by using glob. perldoc glob should give you what you need to use it. It's very useful and i've used it many times before for various different projects. Hope this helps! DKode
__________________
"Mankind cannot define memory, yet it defines mankind" |
|
#3
|
|||
|
|||
|
Yes exactly dir first .. files second
I am thinking:
Result as printed as : aaa [dir] bbb [dir] .... [dir] zzz [dir] aaa.txt [file] bbb.txt [file] .... .txt [file] zzz.txt [file] As per the grooovy graphic's of sorting ![]() |
|
#4
|
|||
|
|||
|
Sample =>While my local computer ON
Try:
Test Computer [ not online at any moment ] http://bkgt21oty8yk.bc.hsia.telus.net/cgi-bin/dir.pl but as you will see dir's and files are mixed. Note : I turn off this computer and reboot often to linux / NT 2000k so try later. |
|
#5
|
|||
|
|||
|
With glob you can grab all the dir names and drop them into one array and then grab all the filenames and drop them into another one.
You would then do: @sorted_dirs = sort(lc($a) cmp lc($b)) @unsorted_dirs; @sorted_files = sort(lc($a) cmp lc($b)) @unsorted_files; print @sorted_dirs; print @sorted_files; Hope that helps to some effect. I have a script with examples of glob but I can't seem to find it right now, try checking out perldoc.com. |
|
#6
|
|||
|
|||
|
Yep Got it to work
I realised after some sleep that I could go back
to the array and do as you show above split them into 2 array's to use. ![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > Sorting Dir above files |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|