[Interest] QFile/QDir: force move mode only?

Scott Bloom scott at towel42.com
Sat May 11 23:44:31 CEST 2019


-----Original Message-----
From: Interest <interest-bounces at qt-project.org> On Behalf Of Henry Skoglund
Sent: Saturday, May 11, 2019 2:22 PM
To: interest at qt-project.org
Subject: Re: [Interest] QFile/QDir: force move mode only?

On 2019-05-11 21:13, Alexander Dyagilev wrote:
> Hello,
> 
> QFile/QDir rename function copies file in the case it's not possible 
> to just move it.
> 
> Is there a  way to learn in advance what type of operation will occur?
> 
> Let's suppose I have 10GB file. In case of copy, I would definitely 
> like to use my own copy function and show UI with the progress of the operation.
> 
> And of course I do not want to use my copy function always if the fast 
> move is available.
> 

Hi, unless you're changing chars in the filename to uppercase/lowercase, where I know QFile tries to help on case-insensitive filesystems, QFile/QDir is pretty much at the mercy of the OS, i.e. if the OS refuses the renaming (for example on NTFS when you try to rename across volumes) then QFile dutifully copies the file instead.

So I think this is not a Qt question and you need to drop down to the OS level, for example on Windows you can call ::MoveFileEx() with the 3rd param = 0, then the call will err out if a copy is needed.
(Note: I haven't tested this myself, just relying on Google :-)

Rgrds Henry
___________________________________
If you are "moving" across a volume, why would you ever want to block the move, simply because in reality it’s a copy?

I would think it would be best, to "move" but allow the OS to do a copy if necessary.

Scott
 


More information about the Interest mailing list