]> git.donarmstrong.com Git - mothur.git/blobdiff - mergefilecommand.cpp
added set.dir command and modified commands to redirect input and output, removed...
[mothur.git] / mergefilecommand.cpp
index fcf63895b960fa8293df03dcff7c1e5bce28c914..d5973394e5a097e879bf1526689d137266a417c1 100644 (file)
@@ -21,7 +21,7 @@ MergeFileCommand::MergeFileCommand(string option){
                }
                else {
                        //valid paramters for this command
-                       string Array[] =  {"input", "output"};
+                       string Array[] =  {"input", "output","outputdir","inputdir"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
@@ -34,10 +34,18 @@ MergeFileCommand::MergeFileCommand(string option){
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
+                       //if the user changes the input directory command factory will send this info to us in the output parameter 
+                       string inputDir = validParameter.validFile(parameters, "inputdir", false);              
+                       if (inputDir == "not found"){   inputDir = "";          }
+                       
                        string fileList = validParameter.validFile(parameters, "input", false);                 
                        if(fileList == "not found") { mothurOut("you must enter two or more file names"); mothurOutEndLine();  abort=true;  }
                        else{   splitAtDash(fileList, fileNames);       }
                        
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       string outputDir = validParameter.validFile(parameters, "outputdir", false);            if (outputDir == "not found")   {       outputDir = "";         }
+                       
+                       
                        numInputFiles = fileNames.size();
                        ifstream testFile;
                        if(numInputFiles == 0){
@@ -46,6 +54,12 @@ MergeFileCommand::MergeFileCommand(string option){
                        }
                        else{
                                for(int i=0;i<numInputFiles;i++){
+                                       if (inputDir != "") {
+                                               string path = hasPath(fileNames[i]);
+                                               //if the user has not given a path then, add inputdir. else leave path alone.
+                                               if (path == "") {       fileNames[i] = inputDir + fileNames[i];         }
+                                       }
+                                       
                                        if(openInputFile(fileNames[i], testFile)){      abort = true;   }
                                        testFile.close();
                                }
@@ -53,6 +67,7 @@ MergeFileCommand::MergeFileCommand(string option){
                        
                        outputFileName = validParameter.validFile(parameters, "output", false);                 
                        if (outputFileName == "not found") { mothurOut("you must enter an output file name"); mothurOutEndLine();  abort=true;  }
+                       else if (outputDir != "") { outputFileName = outputDir + getSimpleName(outputFileName); }
                }
                        
        }