php에서 readdir할때 파일읽어오는 순서

addnull의 이미지

php에서 readdir로 특정 폴더내의
파일리스트를 읽어오는데,
파일을 읽어오는 순서가 엉망이더군요.. ;;
어떤 특정 패턴이 있는것도 아닌것 같고.
매번 읽어올때마다 직접 sort를 해야하는건지
왜 이렇게 순서가 엉망인지 궁금합니다.

제가 해본바론 파일명, 생성 시각, 최종 수정 시각, 최종 사용 시각으로는
읽는 순서가 결정되는 건 아닌것 같습니다.

혹시 파일명의 인코딩 때문에 그럴지도 모른다는 추측을..
비슷한 예로 winamp에서 "add dir"로 mp3를 긁어오면
인코딩 때문인지.. 순서가 엉망이 되더군요.

2006년 2월 21일.

송효진의 이미지

그저 정렬을 하지 않기 때문인것 같네요.
파일시스템도 DB 니까,
쓰고 지우고 하면서 순서가 엉망이 될것 같군요.

php 매뉴얼을 봐도 딱히 정렬관련된게 안보입니다.

그리고 정렬하는거 안귀찮아요.

while(false !== ($f = readdir($fp))) {
    $files[] = $f;
}
sort($files);

끝. 8)
addnull의 이미지

송효진 wrote:
그저 정렬을 하지 않기 때문인것 같네요.
파일시스템도 DB 니까,
쓰고 지우고 하면서 순서가 엉망이 될것 같군요.

php 매뉴얼을 봐도 딱히 정렬관련된게 안보입니다.

그리고 정렬하는거 안귀찮아요.

while(false !== ($f = readdir($fp))) {
    $files[] = $f;
}
sort($files);

끝. 8)

쩝.. 워낙 귀차니즘이.. ;;

rsort를 할 경우가 아니면,
sort는 기본적으로 해줬으면 좋겠어요.
하지만, 다시 생각해보니 아마도 readdir
본연의 기능만 구현하려는 의도인 것 같습니다.

2006년 2월 21일.

ole2000의 이미지

Quote:
Returns the filename of the next file from the directory. The filenames are returned in the order in which they are stored by the filesystem.

php.net 메뉴얼에 이렇게 나오네요.

Be cool...

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.