Results 1 to 5 of 5

Thread: Windows file copy in progress, how can I tell?

  1. #1
    Join Date
    Jan 2009
    Posts
    45
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Windows file copy in progress, how can I tell?

    I want write a program that will syncronize files between two directories.. Suppose (in windows) im copying file(s) into the "from" directory and my program runs to sync the files, I dont want it to try to sync a file that im copying into the "from" directory.. Is there a way to tell if the file is "being copied"?

    Is a file thats "being copied" read-only? If so, can I just try to open the file read-write in my program and if it fails just skip that file?

    Let me know if this doesnt make sense or if more info is needed..

  2. #2
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Windows file copy in progress, how can I tell?

    Hi,

    I had the same problem ago and this is how I solved:

    Before copying the file itself, create a "sameName.lock" file, then copy the file and finally remove the "sameName.lock" file.
    On the other application you have to check if the file "sameName.lock" exists before trying to use it. If it exists, it is being copied and can't access it, if not exists you can access it.

    Maybe there is a better way to do this, but I'm sure that it works.
    Òscar Llarch i Galán

  3. #3
    Join Date
    Jan 2009
    Posts
    45
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Windows file copy in progress, how can I tell?

    Well the problem is, I want to know if windows is copying the file into the directory that im checking.. Does windows create a .lock file or anything like that?

  4. #4
    Join Date
    Nov 2008
    Posts
    142
    Thanks
    3
    Thanked 20 Times in 20 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Windows file copy in progress, how can I tell?

    I don't know for sure if it is the same for Windows (though it would be insane if it behaved different), but on Unix you can't open a file twice to write to it. So you could try opening the file for writing, and if that failed, you would know that some other process is writing to that file, i.e. copying it to the directory at the moment.

    Compared to lock files, the advantage of this approach is that you can detect a copy in progress even if you have no control of how a file is copied to that directory, i.e. "anyone can copy there", in opposition to "only programs you have control of (and that can, in turn, create lock files)" can copy there.

  5. #5
    Join Date
    Jan 2009
    Posts
    45
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Windows file copy in progress, how can I tell?

    Understood.. I just tried to copy something into a directory and tried to run it while it was copying and it gave me a "another program is currently using this file" message.. So ill try to open the file for writing and see if that gives me an error on the open..

    Ill let you all know how it turns out..

Similar Threads

  1. Opening text file fails after autostartup on windows
    By yogourta in forum Qt Programming
    Replies: 2
    Last Post: 18th October 2008, 04:52
  2. file renaming on windows
    By jdd81 in forum Qt Programming
    Replies: 9
    Last Post: 2nd October 2007, 20:41
  3. Draging a non-existing file to the Windows Desktop
    By klaus1111 in forum Qt Programming
    Replies: 13
    Last Post: 20th September 2007, 12:47
  4. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 16:21
  5. Copy progress bar
    By safknw in forum Newbie
    Replies: 13
    Last Post: 16th September 2006, 10:02

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.