PDA

View Full Version : File system utility with more functions than QDir



izico
22nd December 2007, 05:41
Hi,

I need a file system utility with more functions than QDir,especially functionality similiar to rm and mv in Linux coreutils package.
The utility should be portable on all platform Qt supports,and should be C++ class or functions to be used directly(I don't want to use an external program in QProcess,such as a utility like Unix shell).
The mv function seems a little hard to implement by QDir,and to be robust,even rm needs some work(i need the -f -r etc switch functions to work).
Do you have ever written such an utility?And if so,will you share with me?

wysota
22nd December 2007, 12:21
The mv function seems a little hard to implement by QDir,
What is wrong with QDir::rename()?

and to be robust,even rm needs some work(i need the -f -r etc switch functions to work).

Sure it does. QFile::exists(), QDir::entryList() and QDir::entryInfoList() are your friends. Together with QDir::remove() they will allow you to obtain the functionality you seek.

izico
22nd December 2007, 15:32
What is wrong with QDir::rename()?

when newName and oldName are in different partions,QDir::rename(oldname, newName) will hang(at least on one of my system). So I can't use simple if (!rename()) { copy(); remove()};(this works in Posix rename(),as it returns error quickly) I must find a portable way to know if the two are in different partitions,and I find no portable way to do this by now.
Any good idea about this?

wysota
22nd December 2007, 15:44
You could use a dir model, but there is no guarantee if you symlink directories. Maybe the problem with rename() is a problem with your system and not the actual rename?

I just checked Qt sources and it looks like Qt simply performs a copy and delete of the file in question. So the only slowdowns could be caused by performing the copy or finding filepaths.