Question

I'm writing a program to check the file names in a directory and ensure they are following certain standards, one of these standards is that at the end of the file name it should have a version e.g. "file1V01.txt,file1V02.txt...file1V99.txt".

I have it working at the minute with a string array 99 long containing "v01" all the way up to "v99" then running a contains function on the file name string.

My question is, is there a way to make this more efficient as checking a 99 long array every file is quite inefficient. Secondly is it possible to only check the last 3 characters before the file type (e.g. .txt or .docx). so that rather than checking "reallylongfilenamev01.txt" it just checks "v01".txt

Thanks in advance for your time.

     for(int i=0;i<99;++i)
     {
        versioncheck = name.contains(version[i]);
     }
Was it helpful?

Solution

I fixed this myself Using Regex. For the above example I used:

Definition:

QRegExp re("^([V][\\d]*)");

and then the implementation:

if(re3.exactMatch(name.mid(name.length()-10,10)))
{

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top