Results 1 to 5 of 5

Thread: Command Line Arguments: How??

  1. #1

    Thread Starter
    Lively Member Nigorr's Avatar
    Join Date
    Apr 2002
    Location
    Brisbane, Australia
    Posts
    106

    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); 
    
    }

  2. #2
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    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

  3. #3

    Thread Starter
    Lively Member Nigorr's Avatar
    Join Date
    Apr 2002
    Location
    Brisbane, Australia
    Posts
    106
    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.

  4. #4
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    use these

    Code:
    //
    without quotes
    Dont gain the world and lose your soul

  5. #5

    Thread Starter
    Lively Member Nigorr's Avatar
    Join Date
    Apr 2002
    Location
    Brisbane, Australia
    Posts
    106
    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
  •  



Click Here to Expand Forum to Full Width