コード例 #1
0
ファイル: file.cpp プロジェクト: yaoyansi/maya2renderer
boostfs::path findFileNothrow(const std::string& fileName,
		const std::string& searchPath)
{
	boostfs::path filePath = fileName;
	if(filePath.empty())
		return boostfs::path();
	// First check whether the path is complete (often called "absolute") or is
	// relative to the current directory.
	if(filePath.is_complete() || *filePath.begin() == "." || *filePath.begin() == "..")
	{
		if(isRegularFile(filePath))
			return filePath;
		else
			return boostfs::path();
	}
	// In other cases, look for fileName in each path of the searchpath.
	TqPathsTokenizer paths(searchPath);
	for(TqPathsTokenizer::iterator i = paths.begin(), end = paths.end();
			i != end; ++i)
	{
		boostfs::path candidate = (*i)/filePath;
		if(isRegularFile(candidate))
			return candidate;
	}
	return boostfs::path();
}
コード例 #2
0
ファイル: filename.cpp プロジェクト: layeredqueuing/V5
    void
    Filename::backup( const char * filename )
    {
	if ( isRegularFile( filename ) > 0 ) {
	    string backup = filename;
	    backup += "~";
	    rename( filename, backup.c_str() );
	}
    }
コード例 #3
0
ファイル: kfileitem.cpp プロジェクト: vasi/kdelibs
KFileMetaInfo KFileItem::metaInfo(bool autoget, int what) const
{
    if ((isRegularFile() || isDir()) && autoget && !d->m_metaInfo.isValid())
    {
        bool isLocalUrl;
        KUrl url(mostLocalUrl(isLocalUrl));
        d->m_metaInfo = KFileMetaInfo(url.toLocalFile(), mimetype(), (KFileMetaInfo::What)what);
    }
    return d->m_metaInfo;
}
コード例 #4
0
ファイル: bedGraphFile.cpp プロジェクト: arq5x/knotty
// Open the BEDGRAPH file
void BedGraphFile::Open() {
    if (bedGraphFile == "stdin") {
        _bedGraphStream = &cin;
        return;
    }
    // unzipped, regular
    else if ((isGzipFile(bedGraphFile) == false) && (isRegularFile(bedGraphFile) == true)) {
        _bedGraphStream = new ifstream(bedGraphFile.c_str(), ios::in);

        // open an ifstream
        ifstream bedg(bedGraphFile.c_str(), ios::in);

        // can we open the file?
        if ( !bedg ) {
             cerr << "Error: The requested bedgraph file (" << bedGraphFile << ") could not be opened. Exiting!" << endl;
             exit (1);
         }
         else {
             // if so, close it (this was just a test)
             bedg.close();
             // now set a pointer to the stream so that we
             _bedGraphStream = new ifstream(bedGraphFile.c_str(), ios::in);
         }
     }
     else if ((isGzipFile(bedGraphFile) == true) && (isRegularFile(bedGraphFile) == true)) {

        igzstream bedg(bedGraphFile.c_str(), ios::in);
        if ( !bedg ) {
            cerr << "Error: The requested bedgraph file (" << bedGraphFile << ") could not be opened. Exiting!" << endl;
            exit (1);
        }
        else {
            // if so, close it (this was just a test)
            bedg.close();
            // now set a pointer to the stream so that we
            _bedGraphStream = new igzstream(bedGraphFile.c_str(), ios::in);
        }
     }
     else {
         cerr << "Error: Unexpected file type (" << bedGraphFile << "). Exiting!" << endl;
         exit(1);
     }
}
コード例 #5
0
ファイル: filesystem.hpp プロジェクト: Buanderie/mfw2
            std::string extension()
            {
                std::string res;
                if( !isRegularFile() )
                    return std::string("");

                size_t pointPos = _pathStr.find_last_of( '.' );
                if( pointPos == std::string::npos )
                    return std::string("");

                size_t extSize = _pathStr.size() - pointPos;
                res = _pathStr.substr( pointPos, extSize );

                return res;
            }
コード例 #6
0
ファイル: filesystem.hpp プロジェクト: Buanderie/mfw2
            size_t  size()
            {
                if( exists() && isRegularFile() )
                {
					#if defined(__LINUX__)
                    struct stat st;
                    stat(_pathStr.c_str(), &st);
                    return st.st_size;
					#elif defined(__WINDOWS__)
					return 0;
					#endif
                }
                else
                    return 0;
            }
コード例 #7
0
/**
 * Check if a file located at a given path exists.
 */
int Exists(const char* path)
{
	int exists = 0;

	if(isRegularFile(path))
	{	
		FILE* fp = fopen(path, "r");
	
		if(fp != NULL)
		{
			exists = 1;
		}
		
		fclose(fp);	
	}

	return exists;
}
コード例 #8
0
/**
 * Coverts a file located with a given path into a string
 * so that the contents can be worked with without the user needing
 * to do extra work using standard I/O.
 */
char* fileToStringSTDIO(const char* path)
{

	char* string = calloc(1, sizeof(char *));
	int ch = 0;
	int index = 0;

	//Determine whether or not the path is a file
	if(isRegularFile(path))
	{
		//Attempt to open file
		FILE* fp = fopen(path, "r");

		//If the file is NULL proceed no further
		if(fp != NULL)
		{
			//Define a string to hold contents of a file
			string = calloc(bufferSize(fp), sizeof(char *));
			while((ch = fgetc(fp)) != EOF)
			{
				if((char) ch != '\n' || (char) ch != '\t' || (char) ch != '\v' || (char) ch != '\f')
				{
					//printf("char %d %c: \n", index, (char) ch);
					string[index] = (char) ch;
					index++;
				}
				else
				{
					string[index] = ' ';
					index++;
				}
			}

		}

		//Close the file
		fclose(fp);

	}
	// Return the file contents as a string.
	return string;
}
コード例 #9
0
char* fileToStringSYSTEM(const char* path)
{
	char* string = calloc(1, sizeof(char *));
	char* ch = calloc(1, sizeof(char *));
	int index = 0;
	int fd;

	//Determine whether or not the path is a file
	if(isRegularFile(path))
	{
		fd = open(path, O_RDONLY);

		//If file descriptor is that of an error, leave.
		if(fd != -1)
		{
			//Define a string to hold contents of a file
			string = calloc(bufferSizeSYS(fd), sizeof(char *));
			while(read(fd, ch, 1) != 0)
			{
				if(ch[0] != '\n' || ch[0] != '\t' || ch[0] != '\v' || ch[0] != '\f')
				{
					string[index] = ch[0];
					index++;
				}
				else
				{
					string[index] = ' ';
					index++;
				}
			}
		}

		//Close the file
		close(fd);
	}

	//Get rid of buffer
	free(ch);

	//Return the file contents as a string
	return string;
}
コード例 #10
0
ファイル: colours.c プロジェクト: liamwilt/colourS
void collectSourceFile(list * names, list * paths, const char *path) {
    DIR *dp;
    struct dirent *ep;
    char file[MAX_PATH_LEN];
    dp = opendir(path);
    if (dp != NULL) {
        while (ep = readdir(dp)) {
            strcpy(file, path);
            strcat(file, "/");
            strcat(file, ep->d_name);
            if (isSourceFile(ep->d_name) &&
                    isRegularFile(file)) {
                addNode(names, ep->d_name);
                addNode(paths, file);
            }
        }

        (void) closedir(dp);
    } else
        perror("Couldn't open the directory");
}
コード例 #11
0
ファイル: bpfile_UNIX.cpp プロジェクト: Go-LiDth/platform
bool 
isLink(const bfs::path& path)
{
    if (isSymlink(path)) {
        return true;
    }

#ifdef MACOSX
    // aliases appear as regular files
    if (isRegularFile(path)) {
        FSRef ref;
        if (FSPathMakeRef((const UInt8*)path.c_str(), &ref, NULL) == noErr) {
            Boolean isAlias = false, isFolder = false;
            if (FSIsAliasFile(&ref, &isAlias, &isFolder) == noErr) {
                return isAlias;
            }
        }
    }
#endif
    return false;	
}
コード例 #12
0
void KwayMergeSort::OpenTempFiles() {
	for (size_t i = 0; i < _vTempFileNames.size(); ++i) {

		ifstream *file;

		if (isRegularFile(_vTempFileNames[i]) == true) {
			file = new ifstream(_vTempFileNames[i].c_str(), ios::in);
		}
		// gzipped
		//else if ((isGzipFile(_vTempFileNames[i]) == true) && (isRegularFile(_vTempFileNames[i]) == true)) {
		//    file = new igzstream(_vTempFileNames[i].c_str(), ios::in);
		//}

		if (file->good() == true) {
			// add a pointer to the opened temp file to the list
			_vTempFiles.push_back(file);
		} else {
			cerr << "Unable to open temp file (" << _vTempFileNames[i]
					<< ").  I suspect a limit on number of open file handles.  Exiting."
					<< endl;
			exit(1);
		}
	}
}
コード例 #13
0
ファイル: BoostFS.t.cpp プロジェクト: el-bart/ACARM-ng
void testObj::test<1>(void)
{
  ensure("normal file not marked regular", isRegularFile("base.t") );
}
コード例 #14
0
ファイル: FileUtils.cpp プロジェクト: jmeinke/StOAP
bool FileUtils::isRegularFile(const string& path, const string& name) {
  string fileName = path + "/" + name;

  return isRegularFile(fileName);
}
コード例 #15
0
ファイル: File.cpp プロジェクト: PlayWithIt/TFStubserver
/**
 * Recursively visit all files / directories starting at the given directory.
 */
FileVisitor::VisitResult File::visitMe(const VisitOptions &options, unsigned maxDepth) const
{
    FileVisitor::VisitResult vr = FileVisitor::VisitResult::CONTINUE;

    if (isSymlink())
    {
        if (!options.followSymLinks)
            return vr;

        // visit the symlink location instead
        char buf[PATH_MAX];
        ssize_t s = readlink(getFullname().c_str(), buf, sizeof(buf));
        if (s <= 0)
        {
            Log::perror(getFullname());
            throw std::runtime_error(std::string("Cannot read a symlink ") + getFullname());
        }

        // terminate string
        buf[s] = 0;

        if (buf[0] == PATH_SEP_CHAR)
        {
            // absolute link location
            File linked(buf);
            return linked.visitMe(options, maxDepth);
        }
        else {
            // relative link location
            File linked(*this, buf);
            return linked.visitMe(options, maxDepth);
        }
    }

    if (isDirectory())
    {
        if (maxDepth > 0)
        {
            vr = options.visitor.visitDirectory(*this);
            if (vr == FileVisitor::VisitResult::STOP)
                return vr;
            if (vr == FileVisitor::VisitResult::STOP_DIR) {
                options.visitor.afterVisitDirectory(*this);
                return FileVisitor::VisitResult::CONTINUE;
            }

            // recurse with max depth - 1
            vr = recurseInto(options, maxDepth - 1);
            if (vr == FileVisitor::VisitResult::STOP)
                return vr;

            // what to do at end of of directory
            vr = options.visitor.afterVisitDirectory(*this);
        }
    }
    else {
        if (options.visitNonRegular || isRegularFile())
            vr = options.visitor.visitFile(*this);
        else
            vr = FileVisitor::VisitResult::CONTINUE;
    }

    if (vr == FileVisitor::VisitResult::STOP)
        return vr;
    if (vr == FileVisitor::VisitResult::STOP_DIR)
        return FileVisitor::VisitResult::CONTINUE;

    return vr;
}