Exemplo n.º 1
0
/* Get the absolute path of a file. Searches first in PATH.
 * If not found in PATH, will check if fileName is already 
 * an absolute OR relative path.
 * Accepts absolute paths with '~' representing HOME
 * @param: string of the name or path of a file
 * @return: string of absolute path of the file if found. NULL otherwise.
 */
char* getFilePath(char* fileName){
   char** paths = getPaths();
   char* filePath = NULL;
   int i = 0;
   filePath = malloc(PATH_MAX*sizeof(char));

   while( paths[i] != NULL){
       strcpy(filePath, paths[i]);
       strcat(filePath, "/");
       strcat(filePath, fileName);

       if(doesFileExist(filePath)){
	   return filePath;
	}
 
 	i++;
   }
   
   //File was not found in PATH
   strcpy(filePath, fileName);
   filePath = tildaToHome(filePath);
   filePath = realpath(filePath, NULL);

   if( filePath != NULL ){
       return filePath;
   }

	return NULL;
}
Exemplo n.º 2
0
/* void changeDirectory(char* pPath)
 * @desc: Changes the cwd to the speciied path.
 * @input: pPath, specified char* to path.
 * @output: none
 */
void changeDirectory(char* pPath)
{
   int ret;
   char* absPath = tildaToHome(pPath);
   ret = chdir(absPath);
   if(ret == NEG_ONE) {
       printf("I'm sorry Dave, I cannot change to that directory.\n");
   }

   return;
}
Exemplo n.º 3
0
QString Utils::convertPathFromDisplay(const QString &path, bool isFolder)
{
    QString p=path.trimmed();
    if (p.isEmpty()) {
        return p;
    }

    if (p.startsWith(constHttp)) {
        return fixPath(p);
    }
    return tildaToHome(fixPath(QDir::fromNativeSeparators(p), isFolder));
}