code to use all .htm files in a directory

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2004
Posts: 29
Reputation: trashed is an unknown quantity at this point 
Solved Threads: 0
trashed trashed is offline Offline
Light Poster

copy&paste from files

 
0
  #1
Jul 31st, 2005
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

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

but now can i do this

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

?
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,734
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 738
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: code to use all .htm files in a directory

 
0
  #2
Jul 31st, 2005
>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:
  1. char user_path[] = "user_path";
  2. char filename[] = "some_file";
  3. char full_path[BUFSIZ];
  4.  
  5. sprintf ( full_path, "%s/%s.htm", user_path, filename );
  6.  
  7. fp = fopen ( full_path, "r" );
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC