I am starting a new project and i plan to use c# for it. Basically what it entails to is reconfiguring a large am mount of config files. 100+ of them. They are each named differently but are prefixed the same (ex: CONFIG_FILE_xxxxxx , where x changes). Inside the files also follow a similar structure. My question is how would i go about getting started with this. The reconfiguration i plan to do to these files is edit certain parts of the files depending on their name and then saving them. The editing part is going to come from a set amount of fields (ex: ture, false, off, on ..etc) which i plan to hardcode into the program. Open to any suggestions on how about to get started with this. No code please, just suggestions of tools to use.

Recommended Answers

All 3 Replies

Take a look at DirectoryInfo.GetFiles, and the File class. Depending on the size of the files you'll want to look at ReadAllLines and WriteAllLines.

He, that's what I had to do very often during my professional IT period some 25 years ago!
Opening a file, read line by line, make changes according to some "rules" found in another file or in a hard coded table, writing the changed line to a new file, until EOF. Repeat until all files are done. Success!

Your code will be the best "tool" for this.
Even if you could find some third-party software to do this: by the time you finish configuring it to work with your files, you could write something to take care of it.

As ddanbe mentioned, so do I: I still do this kind of file manipulation for one reason or other.

Regular expressions (the Regex class) might serve you well.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.