I am currently writing a program but am beginning to see that I could have problems in the future due to the number of files that I may want to open with too many names to specify individually.
I have a series of .txt files. An unspecified number of them. I would like to open each of them in turn and read the data into my program. I am wondering whether I should copy the code each time I want to open a new file, changing the file specific parts or whether there is a more efficient way of going about it?
At the moment the program is only running on a set of test files but in the future I would be looking to expand it and could potentially have an huge number of files that I would be looking to open.
Also, is there a way of automatically detecting the filename and then using that as the name for say a vector or a variable in my program. I think I am going to really need the program to do this for me.
Thanks for your help! You people here are amazing! :-)
You can feed the program a directory upon starting it, and have it read the contents of that directory, make a list of the contents, identify the files of interest by name, and then operate on each of those.
If you can nail down your requirements a bit more clearly, we can point you at helpful functions.
Ok I think I need to use opendir(). I have found this piece of code but it is currently kicking out all kinds of errors. I was just wondering if someone might be so kind as to talk me through it somewhat. Here is what I have;
Ok I have got the code above to compile now, but what I would like it to be able to do is use it to open first, the first file in a directory. Then I have something I want to do to the data. I then want to move on to the next file and repeat the process.
Am I right in thinking that this code simply open a directory and not much more? I would like to be able to take the name of the first file in the directory and then open that file. Any Ideas how I might be able to achieve this?