seekdir()? what does it do?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers seekdir()? what does it do?
# 1  
Old 01-23-2011
seekdir()? what does it do?

What does seekdir() do exactly?

Does it go through the directory files?

I tried looking it up, but all I got was man pages.

Thanks.
# 2  
Old 01-23-2011
What Operating System and version are you running?
What Shell do you use?
What Programming Language to you use?

Please post some sample code where you are trying to use a "seekdir" function stating what you want to happen and what actually happened.
# 3  
Old 01-23-2011
Hello,

Heres what I found:

SunOS jazzy 5.10 Generic_142900-15 sun4u sparc SUNW,Sun-Blade-1500

I'm using ssh on mac os x terminal and i'm compiling my code using c.

I wanted to know what seekdir does, because I'm trying to write a program that imitates cp copying a filename to a directory.
# 4  
Old 01-23-2011
Remember that a directory is a list of filenames, it is not the files themselves. The readdir, telldir, seekdir functions are for processing a directory. That said, I have never used seekdir (or telldir) for anything. I rather doubt that I ever will. I really can't construct any hypothetical situation where they might be useful.

But if you wanted to write a C program that did the equivalent of "ls /etc", you would opendir() /etc, use readdir() to read the filenames, sort those filnames, and then display them.

When you got to,say, passwd, you could do a telldir() to remember this location in the directory. Then you could use readdir say 5 more times to read the next 5 filenames. Now you could use seekdir to go back to that entry for the file called passwd. Why you would want to do that beats me.
# 5  
Old 01-23-2011
Thanks Perderabo! I wasn't sure how I would be able to use it for what i'm trying to do either. I want to accomplish the simple task of creating a new file to a specified directory, any idea how?

I was reading something that directories cannot be modified and that you cannot write to them directly.
# 6  
Old 01-23-2011
Quote:
Originally Posted by l flipboi l
I wanted to know what seekdir does, because I'm trying to write a program that imitates cp copying a filename to a directory.
You're barking up the wrong tree. chdir() to destination directory, creat() output file, write() to output file. There's more to it, but this at least has you barking up the right tree.
# 7  
Old 01-23-2011
oh man, thanks!!!!!

I will give it a shot..
 
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question