Directory and File Listing in C

Please push me in the right direction :)

Page 1 of 1

6 Replies - 5210 Views - Last Post: 27 May 2008 - 07:28 AM Rate Topic: -----

#1 clargs  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 17-May 08

Directory and File Listing in C

Post icon  Posted 26 May 2008 - 02:09 PM

Hello. I want to code a C program that can list my files and directories. Even just listing only directories or only files can do for beginning. I use Linux, I've found an example but it was written using dir.h library which is not recognized by gcc. I have never tried coding such a program before.

It would be great if you can push me in the right direction, tell me what to search in google or send me some pdf's :D

Thank you B)
clargs

This post has been edited by clargs: 26 May 2008 - 02:14 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Directory and File Listing in C

#2 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1385
  • View blog
  • Posts: 10,962
  • Joined: 06-February 08

Re: Directory and File Listing in C

Posted 26 May 2008 - 02:15 PM

I'm not sure if it's what you're after (I don't work with Linux) but try this link

If you look at the bottom, there's stuff about functions called opendir(), readdir(), and closedir()
Here's a link to the anchor about directories
Hope this helps :)

This post has been edited by gabehabe: 26 May 2008 - 02:15 PM

Was This Post Helpful? 0
  • +
  • -

#3 clargs  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 17-May 08

Re: Directory and File Listing in C

Posted 26 May 2008 - 02:25 PM

View Postgabehabe, on 26 May, 2008 - 02:15 PM, said:

I'm not sure if it's what you're after (I don't work with Linux) but try this link

If you look at the bottom, there's stuff about functions called opendir(), readdir(), and closedir()
Here's a link to the anchor about directories
Hope this helps :)


Thanks for your super fast reply gabehabe :) I've checked them out but they seem a bit compicated at first sight. I'll try to read them now. Ciao :)
Was This Post Helpful? 0
  • +
  • -

#4 clargs  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 17-May 08

Re: Directory and File Listing in C

Posted 26 May 2008 - 02:38 PM

Actually I like low level programming. I want to learn how to read data from harddrives (sectors... etc). Is that very advanced?
Was This Post Helpful? 0
  • +
  • -

#5 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1385
  • View blog
  • Posts: 10,962
  • Joined: 06-February 08

Re: Directory and File Listing in C

Posted 26 May 2008 - 02:41 PM

EDIT:
I think this is what you're looking for.

This post has been edited by gabehabe: 26 May 2008 - 04:22 PM

Was This Post Helpful? 0
  • +
  • -

#6 perfectly.insane  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 70
  • View blog
  • Posts: 644
  • Joined: 22-March 08

Re: Directory and File Listing in C

Posted 27 May 2008 - 03:00 AM

View Postclargs, on 26 May, 2008 - 02:38 PM, said:

Actually I like low level programming. I want to learn how to read data from harddrives (sectors... etc). Is that very advanced?


This might be a bad idea on Linux considering that not everyone uses the same filesystem, but then again, it depends on what you're trying to do.
Was This Post Helpful? 0
  • +
  • -

#7 clargs  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 17-May 08

Re: Directory and File Listing in C

Posted 27 May 2008 - 07:28 AM

@perfectly.insane
You are right I've never thought of that. :)
OK then it would be much better for me to find a nice middle level way to get the list of my files.
Actually I'm aiming to code a program that finds and lists all my mp3 files and writes them in to a database. In linux the music players cannot handle my music archive (~150 GB) the programs I've tried gave errors or just freeze (I've tried like every music player which has library support). So I've decided to write a program (i can write it in other languages but I want to do it in C (maybe C++) to learn how to do it) that writes my mp3's path and names in mysql and after that I'll try to do a music library program...

So I really want to find a way to list my files (recusively?)

Helps appreciated! :)

Happy Coding, :B
clargs
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1