You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

thec0der

Beginner

  • "thec0der" is male
  • "thec0der" started this thread

Posts: 39

Location: Bulgaria

  • Send private message

1

Tuesday, March 24th 2009, 9:35am

QDir entryList problem [SOLVED]

Hello.
Today I found that my function for copying directories does not work correct.
After debug I found that entryList(QDir::AllDirs | QDir::Hidden) contain not only directories, but one file. Actualy..
"there is 2 records about same file ?( ."
There is only one record, but still make wrong decision is directory or file.
This file has a name ".htaccess". No other files make problems.
Can you point me where is the problem?

the function

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
bool Utils::copyDir(const QString source, const QString destination, const bool override) {
	QDir directory(source);
	bool error = false;

	if (!directory.exists()) {
    	return false;
	}

	QStringList dirs = directory.entryList(QDir::AllDirs | QDir::Hidden);
	QStringList files = directory.entryList(QDir::Files | QDir::Hidden);

	QList<QString>::iterator d,f;

	for (d = dirs.begin(); d != dirs.end(); ++d) {
    	if ((*d) == "." || (*d) == "..") {
        	continue;
    	}
#ifdef QT_DEBUG
    	std::cout<< "copyDir dir name " <<(*d).toStdString() << std::endl;
#endif
    	if (!QFileInfo(directory.path() + "/" + (*d)).isDir()) {
        	files << (*d);
        	continue;
    	}

    	QDir temp(destination + "/" + (*d));
    	temp.mkpath(temp.path());

    	if (!copyDir(directory.path() + "/" + (*d), destination + "/" + (*d), override)) {
#ifdef QT_DEBUG
        	std::cout << "copyDir err: "<< (directory.path() + "/" + (*d), destination + "/" + (*d)).toStdString() << std::endl;
#endif
        	error = true;
    	}
	}

	for (f = files.begin(); f != files.end(); ++f) {
    	QFile tempFile(directory.path() + "/" + (*f));
    	QFile destFile(destination + "/" + directory.relativeFilePath(tempFile.fileName()));

    	if (destFile.exists() && override) {
        	destFile.remove();
    	}

    	if (!tempFile.copy(destination + "/" + directory.relativeFilePath(tempFile.fileName()))) {
#ifdef QT_DEBUG
        	std::cout << "copyDir /copy file/ err: "<< (destination + "/" + directory.relativeFilePath(tempFile.fileName())).toStdString() << std::endl;
#endif
        	error = true;

    	}
	}


	return !error;
}

This post has been edited 2 times, last edit by "thec0der" (Mar 24th 2009, 5:19pm)


2

Tuesday, March 24th 2009, 10:38am

Source code

1
2
3
QStringList dirs = directory.entryList(QDir::AllDirs |
    QDir::Hidden // this is the problem !
);
Mandriva Linux release 2009.0 (Official) for i586
Kernel 2.6.27.10-desktop-1mnb on a Dual-processor i686

thec0der

Beginner

  • "thec0der" is male
  • "thec0der" started this thread

Posts: 39

Location: Bulgaria

  • Send private message

3

Tuesday, March 24th 2009, 11:07am

Thanks.. BUT if I have hidden directories? There is no available mask for hidden directories.
As example - ".svn" directory.
Also you can see in line 21 that I make a check "isDir", which prevent adding files to directories list.

Used Qt version 4.3.4, OS Ubuntu 8.04

This post has been edited 1 times, last edit by "thec0der" (Mar 24th 2009, 11:25am)


4

Tuesday, March 24th 2009, 5:12pm

QDir::Hidden will include both hidden directories and hidden files.

By the way, how do you know .htaccess is being considered as a directory ? Is it because you see a :

Source code

1
copyDir dir name .htaccess

message ? But that's because you've placed the debug function before the isDir() check !

A second problem is that your filelist will contain hidden directories as well. Entries found to be directories in dirs should be removed from files.
Mandriva Linux release 2009.0 (Official) for i586
Kernel 2.6.27.10-desktop-1mnb on a Dual-processor i686

thec0der

Beginner

  • "thec0der" is male
  • "thec0der" started this thread

Posts: 39

Location: Bulgaria

  • Send private message

5

Tuesday, March 24th 2009, 5:18pm

8o
Thank you very much!
Problem N2 is my missing piece of puzzle ;)