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

Qt-interest Archive, March 2002
Platform independant way to copy a file?


Message 1 in thread

I need a way to copy a file from path A to path B in Qt.  Anyone know if there is a way to do this?


Message 2 in thread

Hi James,

I believe it was someone on this list that previousely suggested using
QUrlOperator which has a copy() method.  I haven't actually used the method
myself (since we'd already rolled our own - D'oh!).  but from the docs it
looks like it should work.

HTH,
-psj.

> -----Original Message-----
> From: owner-qt-interest@trolltech.com
> [mailto:owner-qt-interest@trolltech.com]On Behalf Of James Hamilton
> Sent: Friday, March 22, 2002 1:20 PM
> To: qt-interest@trolltech.com
> Subject: Platform independant way to copy a file?
>
>
> I need a way to copy a file from path A to path B in Qt.  Anyone
> know if there is a way to do this?
>
> --
> List archive and information: http://qt-interest.trolltech.com
>
>


Message 3 in thread

Here's my copy function.  I haven't actully used it yet but I think it
should work and platform independent too.

bool HUFile::copy(const QString& sIn, const QString& sOut)
{
 QFile fIn(sIn);
 QFile fOut(sOut);
 QByteArray buf(1024);
 Q_LONG nIn;
 bool bResult = true;

 if (fIn.open(IO_ReadOnly))
 {
  if (fOut.open(IO_ReadWrite))
  {
   while ((nIn = fIn.readBlock(buf.data(), buf.size())) > 0)
   {
    if (fOut.writeBlock(buf, nIn) != nIn)
    {
     bResult = false;
    }
   }

   fOut.close();
  }
  else
  {
   bResult = false;
  }

  fIn.close();
 }
 else
 {
  bResult = false;
 }

 return bResult;
}

----- Original Message -----
From: "James Hamilton" <JAMESH@davistl.com>
To: <qt-interest@trolltech.com>
Sent: Friday, March 22, 2002 1:19 PM
Subject: Platform independant way to copy a file?


> I need a way to copy a file from path A to path B in Qt.  Anyone know if
there is a way to do this?
>
> --
> List archive and information: http://qt-interest.trolltech.com
>


Message 4 in thread

This might not be what you had in mind.  But couldn't you just open the file
read the contents and then save it to the new file name in your code.  C
(fread, fwrite) and C++ (iostreams) provide platform independent ways of
doing both of these operations I think.   Perhaps thats not the most
eloquent solution though.

Craig

> ----------
> From: 	James Hamilton[SMTP:JAMESH@davistl.com]
> Reply To: 	JAMESH@davistl.com
> Sent: 	Friday, March 22, 2002 1:19 PM
> To: 	qt-interest@trolltech.com
> Subject: 	Platform independant way to copy a file?
> 
> I need a way to copy a file from path A to path B in Qt.  Anyone know if
> there is a way to do this?
> 
> --
> List archive and information: http://qt-interest.trolltech.com
>