We help IT Professionals succeed at work.
Get Started

Parse a .conf or similar file with different command line "switches" on each line.

Johnjces
Johnjces asked
on
408 Views
Last Modified: 2012-05-05
I am a terrible parser! I have great difficulty and after many lines of redundant delete() and copy() and Pos() functions later I sort of have something sort of working but there must be a  cleaner/better simpler way.

I have a .conf or a .cfg file that I need to parse. Each line in this file is a command line. At a minimum the path and name of another file/executable is needed then various switches which can be in any order. EXxample;

C:\MyWork\MyExecutable.exe                                                { Minimum item required }
C:\Delphi\MyThingy.exe -a c:\readme.txt                               { -a switch then the item follows }
C:\Programs\Stuff\Program.exe -s normal -a c:\readme.txt   { Added -s switch which could be before or after the -a switch and item }

Of course other switches could be added as needed.

The first part of the line must be the executable then the switches (-a, -s, -q and etc.)  that tell me what follows and such can be in any order.

Can anyone point me in the right direction, component or code?

Thanks
Comment
Watch Question
Sr. Software Engineer
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 4 Answers and 52 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE