Results 1 to 18 of 18

Thread: Directory monitoring

  1. #1
    Join Date
    Sep 2014
    Posts
    94
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Directory monitoring

    Hi friends,


    I want an example program for directory monitoring....when i added new files to directory i want to get notifiaction and then it should copy in another folder..........

  2. #2
    Join Date
    Sep 2014
    Posts
    94
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Files list

    Hi friends,

    When added a new files to the directory it should store with QStack plz give me any example

  3. #3
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Files list

    Read about QFileSystemWatcher.

  4. #4
    Join Date
    Apr 2013
    Location
    Prague
    Posts
    258
    Thanks
    3
    Thanked 65 Times in 59 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Directory monitoring

    Look at QFileSystemWatcher class.

  5. #5
    Join Date
    Sep 2014
    Posts
    94
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Filelist

    Hi friends,

    i am added new files to directory and want to get list of files added to Dir and filename...............

  6. #6
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Filelist

    Instead of starting lots of threads with vague statements on the same subject, I suggest you read the documentation for the QDir, QFile and QFileSystemWatcher classes -- see your other threads -- once and for all, and come back with precise descriptions of what you have tried, what works and what you need help with.

  7. The following 2 users say thank you to yeye_olive for this useful post:

    anda_skoa (20th June 2015), d_stranz (15th June 2015)

  8. #7
    Join Date
    Sep 2014
    Posts
    94
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Filelist

    QFileInfo fileInfo;
    QDir path = fileInfo.absoluteDir();
    QDir dir(path);
    QStringList list;
    dir.setNameFilters(list);
    list = dir.entryList( QDir::Files, QDir::Name );
    qDebug() << "List" << list;


    i added this code when i added new files the new file name is coming and what is there in that folder all files it is showing.it should show only what is new file added ....

  9. #8
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Filelist

    You have already had a couple of people tell you to look at QFileSystemWatcher. It can be used to watch a filesystem for directory/file changes, which sounds exactly what you want to do.

    I will say that each OS that provides a service to watch filesystems for changes are notorious (maybe too strong of a word) for not getting 100% reliable notifications. Your mileage may vary, but for apps that absolutely need to catch new files/directories, they typically wind up doing full scans at regular intervals, as well as the filesystem watcher approach.

    You could also take the code you have that provides the QDir::entryList and save all of the results, then rescan at some interval and identify delta's between your saved list and new list, etc.
    Last edited by jefftee; 16th June 2015 at 07:59.

  10. #9
    Join Date
    Sep 2014
    Posts
    94
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Filelist

    i am added 5 files in a dir...i want to get that 5 files in a list....not all the files contain in the folder.....

    given solution look QFilesystemwatcher but i cannot understand..........plz give me one example to help me.....

  11. #10
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Filelist

    Even if you don't want to use QFileSystemWatcher, QDir and QDir::entryInfoList provide everything you need to build a list of all files in a directory.

    You will need to decide what constitutes a "new file" to you. i.e. creation date/time after program startup or after last scan date/time or perhaps you would consider "new files" if they have been modified after your program startup, last scan date/time, etc.

    QFileSystemWatcher can be used to be notified when a directory is updated. If you don't want to use QFileSystemWatcher, then you'll have to re-scan the directories as some interval and use an algorithm to determine if any new files have been created in the directory.

    You can use a container class like QMap<QString, QFileInfo> or QHash<QString, QFileInfo> to keep a list of files. When you re-scan the directory and find a file that isn't already in the map, it's a new file, etc.

    I would also assume you'd want to save the list of files across application restarts, so you'll need a database or file to serialize the filename's to disk.

    Basically, you have a lot to learn in order to successfully write the code to do what you want. I and others have given you enough pointers that you should be able to review the relevant documentation and develop your program. A *huge* part of learning to program is learning how to read, comprehend, and utilize documentation.

    Good luck.
    Last edited by jefftee; 18th June 2015 at 07:43.

  12. #11
    Join Date
    Sep 2014
    Posts
    94
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Filelist

    plz give me example of QFuturewatcher

  13. #12
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Filelist

    Quote Originally Posted by mouni View Post
    plz give me example of QFuturewatcher
    Err... it's QFileSystemWatcher. QFutureWatcher is something else entirely.

    The documentation is crystal clear: construct a QFileSystemWatcher and specify the path of the directory to monitor, then connect to the directoryChanged() signal to get notified when the contents of the directory change.

    In the slot connected to the signal, list the contents of the directory and compare them to a local copy of the previous contents, then react to the changes in any way you see fit.

    Look, you have a long road ahead of you. Show us some code.

  14. #13
    Join Date
    Sep 2014
    Posts
    94
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Filelist

    tell me how to move files from one folder to another folder

  15. #14
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Directory monitoring

    tell me how to move files from one folder to another folder
    Reading docs never killed anyone:
    http://doc.qt.io/qt-5/qfile.html#copy-2

  16. #15
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Directory monitoring

    Quote Originally Posted by stampede View Post
    Reading docs never killed anyone:
    http://doc.qt.io/qt-5/qfile.html#copy-2
    On the same filesystem you can even use rename().

    Cheers,
    _

  17. #16
    Join Date
    Sep 2014
    Posts
    94
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Directory monitoring

    can you give example code

  18. #17
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Directory monitoring

    can you give example code
    Why don't you just post the entire specification for your project here? Maybe someone will put you out of your misery and just write the whole program for you, because you seem to be incapable of writing even the simplest code on your own.

    If you took the time to read the Qt documentation and look at the many, many examples, maybe you wouldn't have to spend so much of your time asking questions here and waiting for us to feed you code from a spoon.

  19. #18
    Join Date
    Sep 2014
    Posts
    94
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Directory monitoring

    how can i declare windows move command in qt

Similar Threads

  1. Replies: 7
    Last Post: 2nd April 2015, 20:48
  2. Replies: 1
    Last Post: 6th January 2014, 15:30
  3. Replies: 0
    Last Post: 19th February 2013, 16:46
  4. QThread implementation for serial port monitoring
    By kpkale in forum Qt Programming
    Replies: 13
    Last Post: 11th July 2012, 15:25
  5. Specify the DLL directory
    By Nyphel in forum Newbie
    Replies: 6
    Last Post: 27th April 2007, 14:29

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.