Violet Giraffe
Violet Giraffe

Reputation: 33607

Check if file can be renamed (moved) without copying

QFile::rename description says:

If the rename operation fails, Qt will attempt to copy this file's contents to newName, and then remove this file, keeping only newName.

That is undesirable. I need to call QFile::rename only if the file can be renamed without copying (e. g. remains on the same disk drive on Windows). Is there a function in Qt that can perform this check (without me having to code it manually for every platform)?

Upvotes: 2

Views: 137

Answers (1)

Violet Giraffe
Violet Giraffe

Reputation: 33607

I've ended up getting and checking the drive number on Windows (PathGetDriveNumber) and drive ID on Unix (stat function and st_dev field of the stat structure). Seems to work as expected so far.

Upvotes: 1

Related Questions