Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 5

Qt-interest Archive, July 2007
[QT 4] How do you remove a directory best?


Message 1 in thread

Please post a code example.

Thanks,
r.


--------------------------------------------------------------------
  Rene Kaiser
  Institute of Information Systems & Information Management
  JOANNEUM RESEARCH Forschungsgesellschaft mbH
  Steyrergasse 17, A-8010 Graz, AUSTRIA

  phone:  +43-316-876-1173                   fax: +43-316-876-1191
  web:    http://www.joanneum.at/iis
  e-mail: mailto:rene.kaiser@xxxxxxxxxxx
-------------------------------------------------------------------- 

--
 [ signature omitted ] 

Message 2 in thread

Kaiser, Rene schrieb:
> Please post a code example.


bool Utils::rmDir (Directory &dir)
{
   Children children = dir.getChildren();

   // make sure 'dir' is empty
   for_each (child in children)
   {
     if (child is a file)
     {
       rmFile (child);
     }
     else
     {
       // recursively delete subdirectory
       rmDir ((Directory)child);
     }
   }
   QDir::rmdir (dir.path());
}

The above pseudo-code does not deal with nasty symbolic links, but you 
get the idea.

Cheers, Oliver

--
 [ signature omitted ] 

Message 3 in thread

 

Despite various suggestions, the folder - "QDir projectDir" - is not deleted. I've tried numerous things, including ...

(A)
  QString folderName = projectDir.dirName();
  QDir parentDir = projectDir;
  parentDir.cdUp();
  bool success = parentDir.rmdir(folderName);


(B)
  QDir dir;
  bool success = dir.rmdir(projectDir.absolutePath());


In both cases "success" turns out to be false, the directory is not deleted. Window's property page tells me it's read only (probable cause?).

BTW, right before trying to delete the folder, I can successfully delete a file in that folder:
  QFile::remove(projectDir.absoluteFilePath(PROJECT_FILE_NAME));


Can anybody help me?


Thanks,
Rene


-----Ursprüngliche Nachricht-----
Von: Kaiser, Rene [mailto:Rene.Kaiser@xxxxxxxxxxx] 
Gesendet: Dienstag, 24. Juli 2007 14:02
An: qt-interest@xxxxxxxxxxxxx
Betreff: [QT 4] How do you remove a directory best?


Please post a code example.

Thanks,
r.


--------------------------------------------------------------------
  Rene Kaiser
  Institute of Information Systems & Information Management
  JOANNEUM RESEARCH Forschungsgesellschaft mbH
  Steyrergasse 17, A-8010 Graz, AUSTRIA

  phone:  +43-316-876-1173                   fax: +43-316-876-1191
  web:    http://www.joanneum.at/iis
  e-mail: mailto:rene.kaiser@xxxxxxxxxxx
-------------------------------------------------------------------- 

--
 [ signature omitted ] 

Message 4 in thread


Just found out what was wrong - another application (wingrep) had somehow locked the directory (why ever ...), that's why the deletion failed.


By the way, 

"error C2660: 'QDir::rmdir' : function does not take 2 arguments"

 

-----Ursprüngliche Nachricht-----
Von: Kaiser, Rene [mailto:Rene.Kaiser@xxxxxxxxxxx] 
Gesendet: Dienstag, 24. Juli 2007 14:44
An: qt-interest@xxxxxxxxxxxxx
Cc: deepa@xxxxxxxxxx; florian.pfanner@xxxxxxxx
Betreff: AW: [QT 4] How do you remove a directory best?

 

Despite various suggestions, the folder - "QDir projectDir" - is not deleted. I've tried numerous things, including ...

(A)
  QString folderName = projectDir.dirName();
  QDir parentDir = projectDir;
  parentDir.cdUp();
  bool success = parentDir.rmdir(folderName);


(B)
  QDir dir;
  bool success = dir.rmdir(projectDir.absolutePath());


In both cases "success" turns out to be false, the directory is not deleted. Window's property page tells me it's read only (probable cause?).

BTW, right before trying to delete the folder, I can successfully delete a file in that folder:
  QFile::remove(projectDir.absoluteFilePath(PROJECT_FILE_NAME));


Can anybody help me?


Thanks,
Rene


-----Ursprüngliche Nachricht-----
Von: Kaiser, Rene [mailto:Rene.Kaiser@xxxxxxxxxxx]
Gesendet: Dienstag, 24. Juli 2007 14:02
An: qt-interest@xxxxxxxxxxxxx
Betreff: [QT 4] How do you remove a directory best?


Please post a code example.

Thanks,
r.


--------------------------------------------------------------------
  Rene Kaiser
  Institute of Information Systems & Information Management
  JOANNEUM RESEARCH Forschungsgesellschaft mbH
  Steyrergasse 17, A-8010 Graz, AUSTRIA

  phone:  +43-316-876-1173                   fax: +43-316-876-1191
  web:    http://www.joanneum.at/iis
  e-mail: mailto:rene.kaiser@xxxxxxxxxxx
-------------------------------------------------------------------- 

--
 [ signature omitted ] 

Message 5 in thread


Just found out what was wrong - another application (wingrep) had somehow locked the directory (why ever ...), that's why the deletion failed.


Sorry,
r.


By the way, does anybody know why the documentation and the compiler don't agree on this?

--> "error C2660: 'QDir::rmdir' : function does not take 2 arguments"
--> bool QDir::rmdir ( const QString & dirName, bool acceptAbsPath ) const  




-----Ursprüngliche Nachricht-----
Von: Kaiser, Rene [mailto:Rene.Kaiser@xxxxxxxxxxx] 
Gesendet: Dienstag, 24. Juli 2007 14:44
An: qt-interest@xxxxxxxxxxxxx
Cc: deepa@xxxxxxxxxx; florian.pfanner@xxxxxxxx
Betreff: AW: [QT 4] How do you remove a directory best?

 

Despite various suggestions, the folder - "QDir projectDir" - is not deleted. I've tried numerous things, including ...

(A)
  QString folderName = projectDir.dirName();
  QDir parentDir = projectDir;
  parentDir.cdUp();
  bool success = parentDir.rmdir(folderName);


(B)
  QDir dir;
  bool success = dir.rmdir(projectDir.absolutePath());


In both cases "success" turns out to be false, the directory is not deleted. Window's property page tells me it's read only (probable cause?).

BTW, right before trying to delete the folder, I can successfully delete a file in that folder:
  QFile::remove(projectDir.absoluteFilePath(PROJECT_FILE_NAME));


Can anybody help me?


Thanks,
Rene


-----Ursprüngliche Nachricht-----
Von: Kaiser, Rene [mailto:Rene.Kaiser@xxxxxxxxxxx]
Gesendet: Dienstag, 24. Juli 2007 14:02
An: qt-interest@xxxxxxxxxxxxx
Betreff: [QT 4] How do you remove a directory best?


Please post a code example.

Thanks,
r.


--------------------------------------------------------------------
  Rene Kaiser
  Institute of Information Systems & Information Management
  JOANNEUM RESEARCH Forschungsgesellschaft mbH
  Steyrergasse 17, A-8010 Graz, AUSTRIA

  phone:  +43-316-876-1173                   fax: +43-316-876-1191
  web:    http://www.joanneum.at/iis
  e-mail: mailto:rene.kaiser@xxxxxxxxxxx
-------------------------------------------------------------------- 

--
 [ signature omitted ] 

Message 6 in thread

Hi Rene,

On Tue, Jul 24, 2007 at 14:52:40 +0200, Kaiser, Rene wrote:
[...]
> By the way, does anybody know why the documentation and the compiler don't agree on this?
> 
> --> "error C2660: 'QDir::rmdir' : function does not take 2 arguments"
> --> bool QDir::rmdir ( const QString & dirName, bool acceptAbsPath ) const  

Are you sure you're looking at the documentation for Qt4?
  http://doc.trolltech.com/4.3/qdir.html#rmdir
  http://doc.trolltech.com/3.2/qdir.html#rmdir

I.e. it was there in Qt 3.2, but not anymore in Qt4.

HTH, Johannes
-- 
 [ signature omitted ] 

Message 7 in thread

This is a case where better errors would help immensely. If another
application is using the directory, I should get a "busy" or "in use" error,
not simply 'failed'.

I could check for a lot of the cases (files in directory, no permissions,
etc.), but there are several problems that can't be checked for why a
directory can't be deleted. It might simply be a device error (general I/O
error), or another application has it open/locked.

I had the same problem in my code, and it took a couple of weeks (on and
off) to find an errant sub-process was holding the directory open (set it as
the CWD).


On 07-24-2007 7:52 AM, "Kaiser, Rene" wrote:

> 
> 
> Just found out what was wrong - another application (wingrep) had somehow
> locked the directory (why ever ...), that's why the deletion failed.
> 
> 
> Sorry,
> r.
> 
> 
> By the way, does anybody know why the documentation and the compiler don't
> agree on this?
> 
> --> "error C2660: 'QDir::rmdir' : function does not take 2 arguments"
> --> bool QDir::rmdir ( const QString & dirName, bool acceptAbsPath ) const
> 
> 
> 
> 
> -----Ursprüngliche Nachricht-----
> Von: Kaiser, Rene [mailto:Rene.Kaiser@xxxxxxxxxxx]
> Gesendet: Dienstag, 24. Juli 2007 14:44
> An: qt-interest@xxxxxxxxxxxxx
> Cc: deepa@xxxxxxxxxx; florian.pfanner@xxxxxxxx
> Betreff: AW: [QT 4] How do you remove a directory best?
> 
>  
> 
> Despite various suggestions, the folder - "QDir projectDir" - is not deleted.
> I've tried numerous things, including ...
> 
> (A)
>   QString folderName = projectDir.dirName();
>   QDir parentDir = projectDir;
>   parentDir.cdUp();
>   bool success = parentDir.rmdir(folderName);
> 
> 
> (B)
>   QDir dir;
>   bool success = dir.rmdir(projectDir.absolutePath());
> 
> 
> In both cases "success" turns out to be false, the directory is not deleted.
> Window's property page tells me it's read only (probable cause?).
> 
> BTW, right before trying to delete the folder, I can successfully delete a
> file in that folder:
>   QFile::remove(projectDir.absoluteFilePath(PROJECT_FILE_NAME));
> 
> 
> Can anybody help me?
> 
> 
> Thanks,
> Rene
> 
> 
> -----Ursprüngliche Nachricht-----
> Von: Kaiser, Rene [mailto:Rene.Kaiser@xxxxxxxxxxx]
> Gesendet: Dienstag, 24. Juli 2007 14:02
> An: qt-interest@xxxxxxxxxxxxx
> Betreff: [QT 4] How do you remove a directory best?
> 
> 
> Please post a code example.
> 
> Thanks,
> r.
> 
> 
> --------------------------------------------------------------------
>   Rene Kaiser
>   Institute of Information Systems & Information Management
>   JOANNEUM RESEARCH Forschungsgesellschaft mbH
>   Steyrergasse 17, A-8010 Graz, AUSTRIA
> 
>   phone:  +43-316-876-1173                   fax: +43-316-876-1191
>   web:    http://www.joanneum.at/iis
>   e-mail: mailto:rene.kaiser@xxxxxxxxxxx
> --------------------------------------------------------------------
> 
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
> 
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
> 
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
> 

Keith Esau
Staff Engineer (dpSHEET)
PDF Solutions, Inc.
keith.esau@xxxxxxx
913-599-6537 (work/home)
913-515-2135 (mobile)
kaesau@xxxxxxxxxxxxx (home/personal)
  
===========================================================================
CONFIDENTIALITY NOTICE: This email contains information that may be
confidential and privileged. Unless you are the intended recipient (or
authorized to receive for the intended recipient), you are prohibited from
reviewing, using, copying, forwarding, keeping, or disclosing to anyone
other than PDF Solutions, Inc. this email or any information in the email
(including any attachment). If you have received this email in error,
please send a reply email only to the sender <keith.esau@xxxxxxx> (delete
the original message body from the reply), and please delete this message
from your system. My apologies for the inconvenience, and thank you in
advance for your cooperation.
===========================================================================


--
 [ signature omitted ] 

Message 8 in thread

Keith Esau schrieb:
> This is a case where better errors would help immensely. If another
> application is using the directory, I should get a "busy" or "in use" error,
> not simply 'failed'.

While this would certainly be very useful this kind of information is 
very platform dependent, not to say file system dependent.

I was in the same situation when exporting PDFs: when the user had 
exported the document and opened this *.pdf with Adobe Reader the file 
becomes "in use". Hence trying to overwrite the same file with a 
successive export operation is not possible: QFile::open() returns 
simply false.

Under Windows there must be a Win32 API which shows more information 
about which process/application has exclusively opened a file, but on 
Unix I'm not sure: the same application could re-export into the same 
*.pdf file even though the Linux Acrobat Reader had it opened at the 
same time, so I'm not even sure if you can open a file exclusively 
(without using file locks which are on application level), let's say on 
a ReiserFS or on a ext2/ext3 file system (I might completely wrong 
though). And even if you could I don't know whether e.g. Linux and/or 
the underlying filesystem provide information about the process which 
has the file in use.

So I don't know whether Qt could support such a extended "Why can't I 
open that file?"-information for all platforms. But you could always use 
the platform-API directly for this... (let me know if you find the 
corresponding win32-API, due to time constraints I did not have the time 
to implement this ;)

Cheers, Oliver

--
 [ signature omitted ] 

Message 9 in thread

On 07-25-2007 4:52 AM, "Till Oliver Knoll" wrote:

> So I don't know whether Qt could support such a extended "Why can't I
> open that file?"-information for all platforms. But you could always use
> the platform-API directly for this... (let me know if you find the
> corresponding win32-API, due to time constraints I did not have the time
> to implement this ;)

But that would defeat the purpose of using Qt (platform independent). :)

The Windoze API is (copied from old code I have):

   DWORD     dwLastError = GetLastError();  // error number from Windoze
   DWORD     dwFormatFlags = FORMAT_MESSAGE_IGNORE_INSERTS |
                FORMAT_MESSAGE_FROM_SYSTEM;
   HMODULE   hModule = NULL;    // default to system source
   char      errbuf[258] = {0,0};

   // If dwLastError is in the network range, load the message source.
   if ((dwLastError >= NERR_BASE) && (dwLastError <= MAX_NERR)) {
      hModule = LoadLibraryEx(TEXT("netmsg.dll"), NULL,
         LOAD_LIBRARY_AS_DATAFILE);

      if (hModule != NULL)
         dwFormatFlags |= FORMAT_MESSAGE_FROM_HMODULE;
   }

   // Call FormatMessage() to allow for message
   // text to be acquired from the system
   // or from the supplied module handle.
   FormatMessageA(dwFormatFlags,
      hModule,   // module to get message from (NULL == system)
      dwLastError,
      MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // default language
     (LPSTR)errbuf, sizeof(errbuf) - 1, NULL);


Keith
**Please do not reply to me, reply to the list.**


--
 [ signature omitted ] 

Message 10 in thread

From the Qt doc:
The directory must be empty for rmdir() to succeed.

you need to recursively go through all files and sub directories in the 
directory you are trying to delete first.

Katrina Niolet

Le Tuesday 24 July 2007 07:43:43 am Kaiser, Rene, vous avez écrit :
> Despite various suggestions, the folder - "QDir projectDir" - is not
> deleted. I've tried numerous things, including ...
>
> (A)
>   QString folderName = projectDir.dirName();
>   QDir parentDir = projectDir;
>   parentDir.cdUp();
>   bool success = parentDir.rmdir(folderName);
>
>
> (B)
>   QDir dir;
>   bool success = dir.rmdir(projectDir.absolutePath());
>
>
> In both cases "success" turns out to be false, the directory is not
> deleted. Window's property page tells me it's read only (probable cause?).
>
> BTW, right before trying to delete the folder, I can successfully delete a
> file in that folder:
> QFile::remove(projectDir.absoluteFilePath(PROJECT_FILE_NAME));
>
>
> Can anybody help me?
>
>
> Thanks,
> Rene
>
>
> -----Ursprüngliche Nachricht-----
> Von: Kaiser, Rene [mailto:Rene.Kaiser@xxxxxxxxxxx]
> Gesendet: Dienstag, 24. Juli 2007 14:02
> An: qt-interest@xxxxxxxxxxxxx
> Betreff: [QT 4] How do you remove a directory best?
>
>
> Please post a code example.
>
> Thanks,
> r.
>
>
> --------------------------------------------------------------------
>   Rene Kaiser
>   Institute of Information Systems & Information Management
>   JOANNEUM RESEARCH Forschungsgesellschaft mbH
>   Steyrergasse 17, A-8010 Graz, AUSTRIA
>
>   phone:  +43-316-876-1173                   fax: +43-316-876-1191
>   web:    http://www.joanneum.at/iis
>   e-mail: mailto:rene.kaiser@xxxxxxxxxxx
> --------------------------------------------------------------------
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body. List archive and information:
> http://lists.trolltech.com/qt-interest/
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body. List archive and information:
> http://lists.trolltech.com/qt-interest/


--
 [ signature omitted ]