![]() |
|
#1
|
|||
|
|||
Questions about handling a batch of files.Hello,
I am trying to handle(read,write and so on) a batch of files named regularly as "name1,name2,name3..."at once. Any body can tell me how to efficiently pass the file name parameter to the handling functions like .read() and .write()? It is a very common question and I think there should be some "formal" solutions.Thank u in advance. nanchuangyeyu |
|||
|
#2
|
|||
|
|||
Re: Questions about handling a batch of files.I am not sure if I understand your question correctly. Let me know if I didn't.
Depending on the regularity of your usage, you may want to generate the file names on the fly in the program, or if the file names are subject to updates, you can put them in a file and subsequently read them into an array of strings. You can then do your routine fopen() or whatever is needed to open the file using each member of the file name array. |
|
#3
|
|||
|
|||
Re: Questions about handling a batch of files.Quote:
2. You can see an example of one way to make integers in a loop be part of a file name in this recent thread: http://www.gidforums.com/t-21148.html Quote:
Well, maybe life would be simpler if there were only one way to do each and every task that is assigned to us, but in C++ there are about a million ways (maybe more) to do most things. Some people use old-fashioned C program approaches that combine integers and "strings" in arrays of chars. The C standard library function sprintf() can do this. Some people use non-standard functions like itoa() to do this (assuming that their compiler libraries contain such a function). I personally think that people learning C++ are best served by learning to take advantage of "C++" ways, and in particular, I consider gratuitous use of char arrays to hold C-style "strings" in 21st century C++ programs to be "so 20th century." But that's just me. I'm funny that way. See Footnote. Regards, Dave Footnote: Note that I said gratuitous use. There certainly are situations where one might make a argument that use of arrays of chars holding C-style "strings" is appropriate. As far as your comment about "formal" methods to accomplish a particular task, Consider the famous quote from Ralph Waldo Emerson: "A foolish consistency is the hobgoblin of little minds." My feelings are that, in general, consistency is a Good Thing in programming, for a lot of reasons, but insistence on a single set way to perform a particular task may not be the most effective way to design applications. Note the modifier "foolish" in the Emerson quote. The big question (to me, at least) is: Who gets to decide what is "foolish"? My pragmatic answer: For most people the person who assigns your grade or who signs your paycheck. That's who. Not some wordy pedant (whom you don't even know) who occasionally spouts off on a public forum on the internet. Last edited by davekw7x : 01-May-2009 at 09:51.
|
|
#4
|
|||
|
|||
Re: Questions about handling a batch of files.Yes , I learned a C++ thing today!
Like dave said If we're in C++ we should do C++. Here are two ways. First I practiced a C style , then I learnt a C++ way. CPP / C++ / C Code:
|
|
#5
|
|||
|
|||
Re: Questions about handling a batch of files.Quote:
I gave an opinion that I personally feel that people learning C++ are "best served" by doing certain things. I didn't take it on myself to say what people "should" do. See Footnote. As in this case we typically have no way of knowing whether Posters are constrained by some specific assignment requirements, and sometimes our advice doesn't really apply to their particular situation. I mean, we try, but... Regards, Dave Footnote: Sometimes I feel really strongly about what they should not do, however, and I try to give the reasons for my objections, rather than just scream that they shouldn't "do that." (You know: "DON'T USE GOTO!" "DON'T USE GETS()." "DON'T EAT YELLOW SNOW!" Stuff like that.) On the other hand, this seems to be my "Emerson" day, so I will mention that he also said, "Sometimes a scream is better than a thesis." I'm guessing that his intent was sardonic, but then again... |
|
#6
|
|||
|
|||
Re: Questions about handling a batch of files.Quote:
I just wanted to acknowledge that I had seen your post and agreed with what you had said. I will do better. (note to self.. do better...) Last edited by Howard_L : 01-May-2009 at 15:11.
|
|
#7
|
|||
|
|||
Re: Questions about handling a batch of files.Quote:
nanchuangyeyu |
Recent GIDBlog
Problems with the Navy (Chiefs) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| jGrasp Compile Error | cardude | C++ Forum | 4 | 29-Sep-2009 21:48 |
| Handling avi files in C/C++...urgent...please!!! | karunr | MS Visual C++ / MFC Forum | 0 | 14-Feb-2008 03:21 |
| Bloodshed Dev C++ Project Options | JdS | C++ Forum | 6 | 11-Nov-2005 18:23 |
| Can't view pages from another machine on the Intranet | aevans | Apache Web Server Forum | 9 | 14-May-2004 03:26 |
| How to create batch files without DOS box? | rhino1616 | Web Design Forum | 3 | 18-Aug-2003 11:00 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The