]> git.donarmstrong.com Git - mothur.git/blobdiff - mothur.h
fixed some bugs found while testing 1.8
[mothur.git] / mothur.h
index 6381e51d626246244b5ce077b9b077337cfc42d8..fdaa06362db6ecda7054fe4ff9b21442487c19d4 100644 (file)
--- a/mothur.h
+++ b/mothur.h
@@ -433,8 +433,8 @@ inline string getPathName(string longName){
  
        string rootPathName = longName;
        
-       if(longName.find_last_of('/') != longName.npos){
-               int pos = longName.find_last_of('/')+1;
+       if(longName.find_last_of("/\\") != longName.npos){
+               int pos = longName.find_last_of("/\\")+1;
                rootPathName = longName.substr(0, pos);
        }
        
@@ -489,7 +489,7 @@ inline bool isBlank(string fileName){
 inline string getFullPathName(string fileName){
        
        string path = hasPath(fileName);
-       string newFileName = getSimpleName(fileName);
+       string newFileName;
        int pos;
        
        if (path == "") { return fileName; } //its a simple name
@@ -501,6 +501,7 @@ inline string getFullPathName(string fileName){
                //get current working directory 
                #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)   
                        if (path.rfind("./") == -1) { return fileName; } //already complete name
+                       else { newFileName = fileName.substr(fileName.rfind("./")+2); } //save the complete part of the name
                        
                        char* cwdpath;
                        size_t size;
@@ -543,6 +544,7 @@ inline string getFullPathName(string fileName){
                                
                #else
                        if (path.rfind(".\\") == -1) { return fileName; } //already complete name
+                       else { newFileName = fileName.substr(fileName.rfind(".\\")+2); } //save the complete part of the name
                                                
                        char *cwdpath = NULL;
                        cwdpath = getcwd(NULL, 0); // or _getcwd
@@ -589,19 +591,15 @@ inline int openInputFile(string fileName, ifstream& fileHandle, string m){
        
        //get full path name
        string completeFileName = getFullPathName(fileName);
-       //string completeFileName = fileName;
 
        fileHandle.open(completeFileName.c_str());
        if(!fileHandle) {
-               mothurOut("Error: Could not open " + completeFileName);  mothurOutEndLine();
                return 1;
-       }
-       else {
+       }else {
                //check for blank file
                gobble(fileHandle);
                return 0;
-       }
-       
+       }       
 }
 /***********************************************************************/
 
@@ -623,6 +621,28 @@ inline int openInputFile(string fileName, ifstream& fileHandle){
        }
        
 }
+/***********************************************************************/
+
+inline int renameFile(string oldName, string newName){
+       
+       ifstream inTest;
+       int exist = openInputFile(newName, inTest, "");
+       
+#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)          
+       if (exist == 0) { //you could open it so you want to delete it
+               inTest.close();
+               string command = "rm " + newName;
+               system(command.c_str());
+       }
+                       
+       string command = "mv " + oldName + " " + newName;
+       system(command.c_str());
+#else
+       remove(newName.c_str());
+       renameOk = rename(oldName.c_str(), newName.c_str());
+#endif
+       return 0;
+}
 
 /***********************************************************************/