X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=mothurout.cpp;h=ee809fafc6e39f6c5cc02d78b513d82704864aa8;hb=f55cf350ca6643f8eb070d8336e1957699a3f109;hp=98f5ce09608855690a9fc7442814841a064db379;hpb=53171f07cc0c0e560e2b4ba2946f690d59fc2dc4;p=mothur.git diff --git a/mothurout.cpp b/mothurout.cpp index 98f5ce0..ee809fa 100644 --- a/mothurout.cpp +++ b/mothurout.cpp @@ -598,6 +598,48 @@ string MothurOut::getPathName(string longName){ } /***********************************************************************/ +bool MothurOut::dirCheck(string& dirName){ + try { + + string tag = ""; + #ifdef USE_MPI + int pid; + MPI_Comm_rank(MPI_COMM_WORLD, &pid); //find out who we are + + tag = toString(pid); + #endif + + //add / to name if needed + string lastChar = dirName.substr(dirName.length()-1); + #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) + if (lastChar != "/") { dirName += "/"; } + #else + if (lastChar != "\\") { dirName += "\\"; } + #endif + + //test to make sure directory exists + dirName = getFullPathName(dirName); + string outTemp = dirName + tag + "temp"; + ofstream out; + out.open(outTemp.c_str(), ios::trunc); + if(!out) { + mothurOut(dirName + " directory does not exist or is not writable."); mothurOutEndLine(); + }else{ + out.close(); + mothurRemove(outTemp); + return true; + } + + return false; + } + catch(exception& e) { + errorOut(e, "MothurOut", "dirCheck"); + exit(1); + } + +} +/***********************************************************************/ + string MothurOut::hasPath(string longName){ try { string path = ""; @@ -972,7 +1014,8 @@ int MothurOut::appendFiles(string temp, string filename) { int numLines = 0; if (ableToOpen == 0) { //you opened it - while(char c = input.get()){ + while(!input.eof()){ + char c = input.get(); if(input.eof()) { break; } else { output << c; if (c == '\n') {numLines++;} } }