opendir() 함수로 ls 명령어를 구현 할수 있나여? 방법좀 알려

phscom의 이미지

opendir() 로 어캐 만드나여
c로 간단하게 구현 해야 하걸랑요.
ㅠ.ㅠ
급한데

맹고이의 이미지

APUE 앞부분에 있어요.

사보세요.

sangwoo의 이미지

opendir(), readdir() 을 사용하시면 간단히는 구현이 가능합니다. 매뉴얼 페이지를 보세요.
ls를 완전히 구현하려면 이것저것 해야 할 것이 많겠지만.. :-)
그리고, dirent.h 에서 struct dirent 와, DIR 도 보시면 좋겠네요.

----
Let's shut up and code.

feanor의 이미지

아주 간단히 짜본 디렉토리 리스팅 소스입니다.

/* listdir.c */

#include <stdio.h>
#include <dirent.h>

void listdir(char *pth)
{
    DIR *dp;
    struct dirent *ep;
    char *np;

    dp = opendir(pth);
    while (1) {
        ep = readdir(dp);
        if (ep == NULL) break;
        np = ep->d_name;
        puts(np);
    }
    closedir(dp);
}

int main()
{
    listdir(".");
    return 0;
}

도움이 되었으면 좋겠습니다.

--feanor

feanor의 이미지

하나 더: 급하다는 소리 하지 마십시오. 질문하는 사람 사정이야 알 바 아니고 답변하는 사람은 하나도 급하지 않습니다. 급하다는 말을 보니 매우 짜증나는군요.

--feanor

liongo의 이미지

P.S stat까지 이용하시면 파일에 정보까지 얻을수 있습니다..

필요할꺼같아서 도움되시라고 적습니다..

그럼..

p.s man stat

ls질문은 정기적으로 올라오는군요 ㅡㅡa
검색도 애용해주시길..

' 형식이 내용을 규정한다. '

saxboy의 이미지

질문의 길이와 어투등등을 감안할때 어딘가에서 1학년이나 2학년 숙제로 ls 를 만들어오라고 한 모양이군요. 숙제마감이 한시간쯤 남았으면 급하지요 ;-)

liongo의 이미지

역시 숙제인건가 ㅡㅡa 어떻게보면 자주올라오는 숙제를 따로
게시판이라도 하나 만들어야 하지 않을까요? ㅋㅋ :D

농담이었습니다 ㅡㅡa

' 형식이 내용을 규정한다. '

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.