C Programming question
Moderator: Thanas
C Programming question
I am doing C course, and was wondering how to write a program that would print out all files in a given directory.
>>Your head hurts.
>>Quaff painkillers
>>Your head no longer hurts.
>>Quaff painkillers
>>Your head no longer hurts.
- Ace Pace
- Hardware Lover
- Posts: 8456
- Joined: 2002-07-07 03:04am
- Location: Wasting time instead of money
- Contact:
Since I don't know C, but you can easily find out the following in C from looking up reference documents.
Step is getting the file list.
Work file by file(in a loop), and print it out using the built in commands.
This is simple enough that it shouldn't give anything away.
Step is getting the file list.
Work file by file(in a loop), and print it out using the built in commands.
This is simple enough that it shouldn't give anything away.
Brotherhood of the Bear | HAB | Mess | SDnet archivist |
- Chris OFarrell
- Durandal's Bitch
- Posts: 5724
- Joined: 2002-08-02 07:57pm
- Contact:
Re: C Programming question
In unix / linux enviroments there are a whole heep of functions that deal with the operating system and manipulating the file system, I think they are in <unistd.h>, <stdio.h> and some others. Visual C++ has a crapload of stuff about manipulating windows ACL's and so on, but I can't remember exactly what.defanatic wrote:I am doing C course, and was wondering how to write a program that would print out all files in a given directory.
Do yourself a favour and go find yourself a library. Unless your assignment is to come up with the solution. Then that's just cheating.
I do know that in IDL it's as easy as
The transpose simply formats the array to print as a column. The first one does a recursive search (which will probably yield a list that is tens of thousands of elements long, mine is 22677). The second will just list the folders and files in that specific directory. This is all useless to you, however, as you're using C, not IDL.
EDIT: I'd also like to point out that in IDL, the comment character is the semi-colon (;), not slash-slash (//).
I do know that in IDL it's as easy as
Code: Select all
directory='c:\' ; or some other directory
print, transpose(file_search(directory, '*'))
;or
files=directory+'*'
print, transpose(file_search(files))
EDIT: I'd also like to point out that in IDL, the comment character is the semi-colon (;), not slash-slash (//).
My brother and sister-in-law: "Do you know where milk comes from?"
My niece: "Yeah, from the fridge!"
My niece: "Yeah, from the fridge!"
Re: C Programming question
Ah, but he has to do it in C, which means directly accessing the Win32 API. No MFC or .NET Framework for him!Chris OFarrell wrote:In unix / linux enviroments there are a whole heep of functions that deal with the operating system and manipulating the file system, I think they are in <unistd.h>, <stdio.h> and some others. Visual C++ has a crapload of stuff about manipulating windows ACL's and so on, but I can't remember exactly what.
- Ace Pace
- Hardware Lover
- Posts: 8456
- Joined: 2002-07-07 03:04am
- Location: Wasting time instead of money
- Contact:
Re: C Programming question
Isn't the Win32 API quite good enough for this sort of work?phongn wrote:Ah, but he has to do it in C, which means directly accessing the Win32 API. No MFC or .NET Framework for him!Chris OFarrell wrote:In unix / linux enviroments there are a whole heep of functions that deal with the operating system and manipulating the file system, I think they are in <unistd.h>, <stdio.h> and some others. Visual C++ has a crapload of stuff about manipulating windows ACL's and so on, but I can't remember exactly what.
Brotherhood of the Bear | HAB | Mess | SDnet archivist |