Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8119781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:54:30+00:00 2026-06-06T04:54:30+00:00

I’m trying to write a basic synchronisation program to copy files between two directories.

  • 0

I’m trying to write a basic synchronisation program to copy files between two directories.

The plan is to have some sort of database of the files which were already copied so when the program scans through the directory it can pick out what it has already copied and what it needs to copy again, i.e. modified or new files.

One of the problems which I’m not sure how to approach is how should I deal with files which are renamed by the user. How can i tell that a renamed file is actually the same file as one listed in the database, albeit with a different name. Is there an underlying file ID that the program could extract? I’d like the code to be portable so that probably makes this more difficult considering filesystems will be different.

I was thinking that I could make note of the size and creation date of each file and keep that information in the database to determine if the file was actually just renamed. If two files have the same information size/date I could store a hash or something to tell them apart but I dont know how efficient that’d be.

Any suggestions? (I’m using C++/QT)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T04:54:32+00:00Added an answer on June 6, 2026 at 4:54 am

    To track changes to files in a given folder while your application is running, see QFileSystemWatcher, with which you can track all file changes within a directory after calling QFileSystemWatcher::addPath("directory/to/watch/"):

    The fileChanged() signal is emitted when a file has been modified,
    renamed or removed from disk. Similarly, the directoryChanged() signal
    is emitted when a directory or its contents is modified or removed.
    Note that QFileSystemWatcher stops monitoring files once they have
    been renamed or removed from disk, and directories once they have been
    removed from disk.

    In order to keep tracking the files once they have been renamed, just re-enable watching them using QFileSystemWatcher::addPath() again.


    When your application wasn’t running during the rename operation, you have to watch the contents of the file (if you also want to cover the case when a file has been deleted and copied back, where the inode on linux / whatever on other file system types has changed).

    This can be done using MD5 sums, but it requires your application to read the whole file, which can be slow for files greater than, let’s say, 10 megabytes. If this drawback is acceptable, just save the MD5 sum returned by QCryptographicHash::hash(file.readAll(), QCryptographicHash::Md5). Of course, there are some corner cases where you have hash collisions, but for most applications this should not be a problem. But please note, that it can happen that you will not detect a change of the contents. Also note that the simple one-liner above is blocking and reads the whole file into memory before computing the MD5 sum. Use the step-wise MD5 sum calculation provided by QCryptographicHash (using addData() and result() instead) to “stream” the file into the MD5 calculation.

    Comparing the file sizes before reading the whole contents instead of creating the MD5 sum will work in most cases (it happens not too often that a change results in the same file size; and in such cases you could fall back to the MD5 sum comparison). But after you noticed a change, you need to read the MD5 sum anyway, to be able to detect future changes!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have thousands of HTML files to process using Groovy/Java and I need to
I have a bunch of posts stored in text files formatted in yaml/textile (from
I am trying to loop through a bunch of documents I have to put
I have some data like this: 1 2 3 4 5 9 2 6
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.