
Welcome to PcCare.com
| How to read command line arguments with c# | |
static int Main(string[] args) { int ReturnStatus = 0; int index = 0; ID3v1 mp3File = new ID3v1(); string text; string ArgName; while (index < args.Length) { text = args[index].ToUpper(); ArgName = "/FILENAME:"; ArgName = ArgName.ToUpper(); if (text.StartsWith(ArgName)) { mp3File.filename = args[index].Substring(ArgName.Length); } ArgName = "/TITLE:"; ArgName = ArgName.ToUpper(); if (text.StartsWith(ArgName)) { mp3File.ValuesToWrite.Title = args[index].Substring(ArgName.Length); } ArgName = "/ARTIST:"; ArgName = ArgName.ToUpper(); if (text.StartsWith(ArgName)) { mp3File.ValuesToWrite.Artist = args[index].Substring(ArgName.Length); } ArgName = "/Album:"; ArgName = ArgName.ToUpper(); if (text.StartsWith(ArgName)) { mp3File.ValuesToWrite.Album = args[index].Substring(ArgName.Length); } ArgName = "/Year:"; ArgName = ArgName.ToUpper(); if (text.StartsWith(ArgName)) { mp3File.ValuesToWrite.Year = args[index].Substring(ArgName.Length); } ArgName = "/Comment:"; ArgName = ArgName.ToUpper(); if (text.StartsWith(ArgName)) { mp3File.ValuesToWrite.Comment = args[index].Substring(ArgName.Length); } ArgName = "/Write:"; ArgName = ArgName.ToUpper(); if (text.StartsWith(ArgName)) { mp3File.ReadTags = (!(Convert.ToBoolean(args[index].Substring(ArgName.Length)))); } index = index + 1; } if (mp3File.filename.Length == 0 || mp3File.filename.Length == 0) { Console.Error.WriteLine("\n\nMp3TagWrite invalid command line argument. usage: Mp3TagWrite /filename:'c:\\temp\\Dark Side Of the Moon.Mp3' /Write:True /Artist:'Pink Floyd' [Title,Album,Year,Comment]"); Console.Error.WriteLine("/Write:True writes tags to file, /Write:False read tags from file"); return (1); } try { // read current values from mp3 file mp3File.Read(); if (!mp3File.ReadTags) { // read current values mp3File.updateMP3Tag(); // Read to print new values mp3File.Read(); } Console.WriteLine("\n\nFilename: {0}", mp3File.filename); Console.WriteLine("Title: {0}", mp3File.CurrentValues.Title); Console.WriteLine("Artist: {0}", mp3File.CurrentValues.Artist); Console.WriteLine("Album: {0}", mp3File.CurrentValues.Album); Console.WriteLine("Year: {0}", mp3File.CurrentValues.Year); Console.WriteLine("Comment: {0}", mp3File.CurrentValues.Comment); return(ReturnStatus); } catch (Exception e) { Console.Error.WriteLine("\n\n{0}",e.ToString()); ReturnStatus = 1; } return (ReturnStatus); } }
|
DISCLAIMER: It is assumed that users are familiar with the operating system they are using and comfortable with making the suggested changes. PcCare.com will not be held responsible if changes you make cause a system failure.
Please review our Terms of Service and Privacy statement before initiating service or using this site. Microsoft® and the Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. PcCare Site Map. About Us |