creating a directory & links to the files in that directory

shyma_nk
shyma_nk used Ask the Experts™
on
i have to do the following tasks:
1.my program generates several output files.these files i need to store in a directory which also need to be created by the code itself.will the following command generate a new directory if it doesn't exist?
  DIR *dirp;
  dirp = opendir("/var/tmp/store")
 here 'store' is the new directory which is to be created. if this won't work what may be the reason ? & is there any solution to this problem other than manually generating the directory with the command mkdir in the command prompt.

2.the output files generated should be stored in the new directory.along with this i have to create links to each & every file that is created & store that links in one existing directory.

3.one more option is to remove the new directory generated above.is there any command to remove an existing directory.when this is to be done the links to all files also need to be removed.can the
unlink(filename) command can be used to remove the links ?

can anyone help me with these problems?

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
obg

Commented:
1. I don't know, though I feel that I should. I'd use the system("mkdir /var/tmp/store"); until I found a better solution...

2. Use symlink(char *link, char *path); to create links.

3. Likewise, use system("rm -rf /var/tmp/store");

Commented:
to create new dirs, use mkdir(const char *path, mode_t mode)

to create links,
  symlink(const char *name1, const char *name2)

refer man pages for errors.

obg

Commented:
Hey... There is a mkdir(char *path, mode_t mode); in sys/stat.h. Mode is the usual file mode flags:

      The value of the argument mode is the bitwise inclusive OR of the
      values of the desired permissions.

           S_IRUSR        Read by owner.
           S_IWUSR        Write by owner.
           S_IXUSR        Execute (search) by owner.
           S_IRGRP        Read by group.
           S_IWGRP        Write by group.
           S_IXGRP        Execute (search) by group.
           S_IROTH        Read by others (that is, anybody else).
           S_IWOTH        Write by others.
           S_IXOTH        Execute (search) by others.

And of course, there is also a rmdir(char *path);
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

obg

Commented:
@#¤$%&! - You beat me by 2 minutes... :-(

Author

Commented:
how to remove the links .i have to search the directory & find out the links then remove it.is there any command to test whethjer the directory contents are normal files or special files i mean any links .
obg

Commented:
Ah... remove(char *path);

Author

Commented:
i asked how to find which entry in a directory is  the link & which entry is a normal file.

Author

Commented:
i asked how to find which entry in a directory is  the link & which entry is a normal file.
Commented:
Ah, sorry. I'm running short on time here, but does stat() or fstat() give you any info?

Author

Commented:
i asked how to find which entry in a directory is  the link & which entry is a normal file.

Author

Commented:
i asked how to find which entry in a directory is  the link & which entry is a normal file.
obg

Commented:
Ehh... And we heard you the previous two times.

Author

Commented:
i think i clicked many times on the same comment .my question is to find the links in a directory.means i have to open a directory check all contents & remove all link files present. hope u understood my question

Author

Commented:
i think i clicked many times on the same comment .my question is to find the links in a directory.means i have to open a directory check all contents & remove all link files present. hope u understood my question
obg

Commented:
opendir and readdir will do that for you, if I'm not misstaken (again). I THINK you can use fstat to see whether it is a link or a file.
obg

Commented:
BTW, dont you create the links yourself? I mean, is there a way to "remember" which ones were links?

Author

Commented:
i think i clicked many times on the same comment .my question is to find the links in a directory.means i have to open a directory check all contents & remove all link files present. hope u understood my question

Author

Commented:
thereis no way to remember the names because the name of the links depend on the input given to the program so it will vary.i couldn't understand what this fstat does that's why i asked is there any other way.could u explain me briefly abt this function.i have a doubt like when the file is a link file it will be having some special character right.like when we do ls -l command the 1st character will be either - or d like that is there any other feature upon that we should be possible to identify that feature.is there any answer to ths question?
obg

Commented:
I am sorry, perhaps I missed something... I ran the stat() function, and I was pretty sure that the st_mode would tell the difference. It obviously does not... :-(

Author

Commented:
i didn't get any answer to my question.i'm asking again is there any way to identify the entries in a directory which are links to some other files?

Author

Commented:
stat function will satisfy my requirement.thank you for your help
obg

Commented:
Yeah...? That's very good, and thanks for the score!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial