0

hi.
question 1:
i am writing a small C script to convert files to another format.
in this case i need my script to use all files in a directory that have extension .htm - how can i do this?
the user will manually specify the directory path but then i want the software to find all .htm files and take their contents to paste them in another file

question 2:
after the user wrote the directory's path (eg. /home/frank/mywebsite) it will save it in a char variable.
when i need to open a certain file I have to specify the path myself, like this

fp = fopen("/var/tmp/string.txt", "r")

but now can i do this

fp = fopen("user_path/some_file.htm", "r")

?

2
Contributors
1
Reply
2
Views
11 Years
Discussion Span
Last Post by Narue
0

>i need my script to use all files in a directory
You can search a directory with opendir and readdir and closedir. Check your man pages for details.

>but now can i do this
You need to build the path string manually:

char user_path[] = "user_path";
char filename[] = "some_file";
char full_path[BUFSIZ];

sprintf ( full_path, "%s/%s.htm", user_path, filename );

fp = fopen ( full_path, "r" );
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.