944,210 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 1827
  • C RSS
Jul 31st, 2005
0

copy&paste from files

Expand Post »
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")

?
Similar Threads
Reputation Points: 11
Solved Threads: 0
Light Poster
trashed is offline Offline
30 posts
since Oct 2004
Jul 31st, 2005
0

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

>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" );
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Getting the time from GetSystemTime
Next Thread in C Forum Timeline: File I/O Help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC