Beispiel #1
0
void FindFileImpl::find( QString directory )
{
    //save the folder only if the search is just beginning
    if(m_recursiveDepth==0) {
        m_searchDirectory=directory;
    }
    m_recursiveDepth++; //search is one-level deeper
    
    QDir dir(directory);
    QString filterNames = comboFileTypes->currentText();
    filterNames.remove(" ");
    QFileInfoList list = dir.entryInfoList(filterNames.split(";"), QDir::AllDirs | QDir::Files | QDir::NoSymLinks | QDir::NoDotAndDotDot);
    foreach(QFileInfo fileInfo, list)
    {
        qApp->processEvents();
        if ( m_stop )
            return;
        if ( fileInfo.isFile() )
        {
            findInFile( fileInfo.absoluteFilePath() );
        }
        else if ( checkRecursive->isChecked() )// Directory
        {
            find( fileInfo.absoluteFilePath() );
        }
    }
Beispiel #2
0
int main(int argc, char** argv)
{
    if(argc != 3)
    {
        fprintf(stderr, "Usage: %s <string> <filename>\n", argv[0]);
        return 1;
    }
    
    
    struct stat f_stat;
    char* filename = argv[2];
    
    //check if given arg is a file
    if(stat(argv[2], &f_stat) == -1 ){
        fprintf(stderr, "%s does not exist or could not stat.\n", filename);
        return 1;
    }
        
    if(S_ISREG(f_stat.st_mode))
    {
        findInFile(argv[1], filename);
        return 0;
    }
    //not a regular file
    fprintf(stderr, "%s is not a regular file.\n", filename);
    return 1;
}
Beispiel #3
0
/**
 * The passed QRegExp is copied. Use the other findInFile function to access
 * the RegExp.
 *
 * Throws FileOpenError
 *
 * @param filename
 * @param regexp
 * @return
 */
QString findInFile (const QString &filename, const QRegExp &regexp, int group)
{
	// Make a copy because apparenly we cannot capture in a const QRegExp (but
	// we want to pass a const& so we can use an anonymous value in calls).
	QRegExp re (regexp);

	if (findInFile (filename, re))
		return re.cap (group);
	else
		return QString ();
}