Results 1 to 8 of 8

Thread: Problem with Copying files and checking exists or not?

  1. #1
    Join Date
    Sep 2013
    Posts
    33
    Thanks
    5
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Exclamation Problem with Copying files and checking exists or not?

    I am copying a bunch of files to a folder and checking , what are the new files copied( by QFileSystemWatcher ).
    I am performing some task with newly copied files.
    But sometimes it fails, bcoz during copy although QFile(fileName).exists() returns true, but physically file not present.

    SO what should I do to overcome his situation particularly during copy.
    Thanks in advance.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,325
    Thanks
    36
    Thanked 1,527 Times in 1,478 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem with Copying files and checking exists or not?

    Copying a file is not an instant operation, so the file can appear in the directory before it is fully copied.

    Do you have control over the program doing the copying?

    Cheers,
    _

  3. #3
    Join Date
    Sep 2013
    Posts
    33
    Thanks
    5
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Problem with Copying files and checking exists or not?

    No I ve no control. Because the copy process starts by OS copy operation.
    Quote Originally Posted by anda_skoa View Post
    Copying a file is not an instant operation, so the file can appear in the directory before it is fully copied.

    Do you have control over the program doing the copying?

    Cheers,
    _

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    3,987
    Thanks
    232
    Thanked 628 Times in 618 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Problem with Copying files and checking exists or not?

    So what does QFileInfo return when you ask for the file size? Zero? Non-zero? If it returns zero at first, then the actual file size only after the copy operation is complete, then you could start a QTimer when the files first appears (QFileSystemWatcher::directoryChanged()) and check every second or so to look for a non-zero size.

    What happens if in your QFileSystemWatcher::directoryChanged() slot you add a connection to the fileChanged() slot? Does that get called when the file copy is finished?

  5. #5
    Join Date
    Sep 2013
    Posts
    33
    Thanks
    5
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Problem with Copying files and checking exists or not?

    It also fails. loading non zero size image file gives unexpected result.
    Quote Originally Posted by d_stranz View Post
    So what does QFileInfo return when you ask for the file size? Zero? Non-zero? If it returns zero at first, then the actual file size only after the copy operation is complete, then you could start a QTimer when the files first appears (QFileSystemWatcher::directoryChanged()) and check every second or so to look for a non-zero size.

    What happens if in your QFileSystemWatcher::directoryChanged() slot you add a connection to the fileChanged() slot? Does that get called when the file copy is finished?

  6. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    3,987
    Thanks
    232
    Thanked 628 Times in 618 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Problem with Copying files and checking exists or not?

    It also fails. loading non zero size image file gives unexpected result.
    I don't know what this means. How does it fail? What is the "unexpected result"?

  7. #7
    Join Date
    Sep 2013
    Posts
    33
    Thanks
    5
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Problem with Copying files and checking exists or not?

    The size is non zero, but when loading image file with QImage, it gives me a data of partial image.Anyway to solve this.Thank you.
    Quote Originally Posted by d_stranz View Post
    I don't know what this means. How does it fail? What is the "unexpected result"?

  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,325
    Thanks
    36
    Thanked 1,527 Times in 1,478 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem with Copying files and checking exists or not?

    If it fails because of unfinished copy, you will have to try again later.

    Alternatively you can try to let the file system watcher only start/restart a timer and read the file when the timer runs out.
    That of course depends on whether the file system watcher will signal file changes during the copy.

    There is no ideal solution because you can't fix the program that is doing the copying.

    Cheers,
    _

Similar Threads

  1. Replies: 1
    Last Post: 28th April 2011, 13:16
  2. Replies: 2
    Last Post: 21st February 2011, 14:52
  3. problem copying files and unmount drives
    By alejo in forum Qt Programming
    Replies: 2
    Last Post: 14th July 2009, 20:54
  4. Only copying files using qmake
    By sagacity in forum Installation and Deployment
    Replies: 2
    Last Post: 26th June 2009, 14:03
  5. Replies: 2
    Last Post: 5th September 2007, 22:31

Tags for this Thread

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.