|
-
Sep 12th, 2002, 01:07 AM
#1
Thread Starter
Lively Member
Command Line Arguments: How??
I have the following code. It is just the main part.
How do I use command line arguments to control which section of code is executed??
Code:
public static void Main(string[] args) {
string fromDir;
DateTime startTime = DateTime.Now;
Console.WriteLine("Copy SCO files from CDSWEB to local Tomcat folder");
//Do this with -lib
startInt = 39;
fromDir = "F:\\Jdev9i_conf\\mywork\\SCO\\SCO_Main\\lib";
toDir = "C:\\Java\\Apache\\Tomcat\\webapps\\sco\\WEB-INF\\lib\\";
ProcessDirectory(fromDir);
//Do this with -html
startInt = 47;
fromDir = "F:\\Jdev9i_conf\\mywork\\SCO\\SCO_Main\\public_html";
toDir = "C:\\Java\\Apache\\Tomcat\\webapps\\sco\\";
ProcessDirectory(fromDir);
//Do this with -class
startInt = 43;
fromDir = "F:\\Jdev9i_conf\\mywork\\SCO\\SCO_Main\\classes";
toDir = "C:\\Java\\Apache\\Tomcat\\webapps\\sco\\WEB-INF\\classes\\";
onlyFileType = ".class";
excludeFolder = ".jsps";
ProcessDirectory(fromDir);
}
-
Sep 12th, 2002, 10:19 AM
#2
Frenzied Member
You would need to do switch statement.
This is how you would do it
Code:
//main entry point for program
public static void Main(string[] args){//this is what takes the command line arguments
string fromDir;
DateTime startTime = DateTime.Now;
Console.WriteLine("Copy SCO files from CDSWEB to local Tomcat folder");
switch(args){
case "-lib": //Do this with -lib
startInt = 39;
fromDir = "F:\\Jdev9i_conf\\mywork\\SCO\\SCO_Main\\lib";
toDir = "C:\\Java\\Apache\\Tomcat\\webapps\\sco\\WEB-INF\\lib\\";
ProcessDirectory(fromDir);
break;
case "-html": //Do this with -html
startInt = 47;
fromDir = "F:\\Jdev9i_conf\\mywork\\SCO\\SCO_Main\\public_html";
toDir = "C:\\Java\\Apache\\Tomcat\\webapps\\sco\\";
ProcessDirectory(fromDir);
break;
case "-class": //Do this with -class
startInt = 43;
fromDir = "F:\\Jdev9i_conf\\mywork\\SCO\\SCO_Main\\classes";
toDir = "C:\\Java\\Apache\\Tomcat\\webapps\\sco\\WEB-INF\\classes\\";
onlyFileType = ".class";
excludeFolder = ".jsps";
ProcessDirectory(fromDir);
break;
default:
Console.WriteLine("usage incorrect ....");
break;
}
}
Hope that helped
Dont gain the world and lose your soul
-
Sep 12th, 2002, 05:15 PM
#3
Thread Starter
Lively Member
Thankyou, that was pretty easy, I have been using JAVA and didn't think switch took a string, because in JAVA it only accepts type int.
But this would only take the first arugment, wouldn't it? So I would actually need,
Code:
//main entry point for program
public static void Main(string[] args){//this is what takes the command line arguments
string fromDir;
DateTime startTime = DateTime.Now;
Console.WriteLine("Copy SCO files from CDSWEB to local Tomcat folder");
foreach(string args1 in args) {
switch(args1){
case "-lib": //Do this with -lib
startInt = 39;
fromDir = "F:\\Jdev9i_conf\\mywork\\SCO\\SCO_Main\\lib";
toDir = "C:\\Java\\Apache\\Tomcat\\webapps\\sco\\WEB-INF\\lib\\";
ProcessDirectory(fromDir);
break;
case "-html": //Do this with -html
startInt = 47;
fromDir = "F:\\Jdev9i_conf\\mywork\\SCO\\SCO_Main\\public_html";
toDir = "C:\\Java\\Apache\\Tomcat\\webapps\\sco\\";
ProcessDirectory(fromDir);
break;
case "-class": //Do this with -class
startInt = 43;
fromDir = "F:\\Jdev9i_conf\\mywork\\SCO\\SCO_Main\\classes";
toDir = "C:\\Java\\Apache\\Tomcat\\webapps\\sco\\WEB-INF\\classes\\";
onlyFileType = ".class";
excludeFolder = ".jsps";
ProcessDirectory(fromDir);
break;
default:
Console.WriteLine("usage incorrect ....");
break;
}
}
}
How do you get your code to indent I have tried using tabs and spaces but it doesn't work, do i need to put in "& nbsp ;"??
Last edited by Nigorr; Sep 12th, 2002 at 08:49 PM.
-
Sep 12th, 2002, 08:45 PM
#4
Frenzied Member
Dont gain the world and lose your soul
-
Sep 12th, 2002, 08:50 PM
#5
Thread Starter
Lively Member
I forgot to close the code tag so i had two of these "[ code ]"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|