Results 1 to 10 of 10

Thread: file renaming on windows

  1. #1
    Join Date
    May 2007
    Posts
    9
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default file renaming on windows

    Hi!

    I am trying to move a file using QFile::rename() but the results are more like a copy operation. The file gets copied to the new file name, but it still seems to exist at the old file name as well. I have also tried QDir::rename with the same result.

    Calling QFile:: exists shows that the original file exists, but using QFile::remove to delete the original file fails with an error code of QFile::NoError. You can delete the file manually.

    Using QFileInfo:: permission, it looks like the owner, user, and others groups have write permission to the file.

    We build our application for both linux and windows, and under Linux the above scenario works as you would expect, and the file is moved from one name to another.

    Has anyone else run into this?

    Thanks,
    Jesse

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: file renaming on windows

    Does rename returns true or false?

  3. #3
    Join Date
    May 2007
    Posts
    9
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: file renaming on windows

    The rename returns true.

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: file renaming on windows

    Are you trying "move" the file across partitions/hard drives or the destination is on the same partition as the source?

  5. #5
    Join Date
    May 2007
    Posts
    9
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: file renaming on windows

    Same partition / drive. It is actually in the same directory. I want to move the file so I can copy a file to its original name.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: file renaming on windows

    Maybe you could use QTemporaryFile instead?

  7. #7
    Join Date
    May 2007
    Posts
    9
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: file renaming on windows

    Thanks for the suggestion, but I'm not sure that will work the way I want it to.

    I am basically working on a save mechanism where there is a saved file, and a working file. On a save operation, I want to move the saved file to a temporary name, copy the working file to the saved file name, and then delete the temporary file on success, or rename it back to the saved file if the copy fails. The rename is key, because copying the working file to the save file is the goal, and the rename will free up the save file name.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: file renaming on windows

    Check if you are not trying to delete an opened file.

  9. #9
    Join Date
    May 2007
    Posts
    9
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: file renaming on windows

    Doh! Yes, that was the problem. The file was being opened with a QLockedFile somewhere else in the program. Funny how that didn't stop the operation on Linux!

    Anyway, thank you both very much for your help. I still have some hair left.

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: file renaming on windows

    Quote Originally Posted by jdd81 View Post
    Funny how that didn't stop the operation on Linux!
    The reason is simple. Windows uses mandatory locking while Linux uses advisory locking thus it is possible to ignore the lock on Linux but not on Windows (the latter causes inability to reopen a file after a crash of an application holding a lock to the open file).

Similar Threads

  1. Draging a non-existing file to the Windows Desktop
    By klaus1111 in forum Qt Programming
    Replies: 13
    Last Post: 20th September 2007, 12:47
  2. Replies: 3
    Last Post: 4th September 2007, 15:40
  3. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 16:21
  4. Qt, Windows and cygwin --- crt0.o: No such file ...?
    By TheRonin in forum Qt Programming
    Replies: 1
    Last Post: 27th October 2006, 11:16
  5. QProcess problem with windows batch file
    By bood in forum Qt Programming
    Replies: 11
    Last Post: 6th January 2006, 09:08

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.