PDA

View Full Version : Directory monitoring



mouni
11th June 2015, 12:53
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..........

mouni
11th June 2015, 13:00
Hi friends,

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

Lesiok
11th June 2015, 13:22
Read about QFileSystemWatcher.

Radek
11th June 2015, 16:29
Look at QFileSystemWatcher class.

mouni
15th June 2015, 07:07
Hi friends,

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

yeye_olive
15th June 2015, 14:20
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.

mouni
16th June 2015, 05:55
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 ....

jefftee
16th June 2015, 07:03
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.

mouni
18th June 2015, 07:14
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.....

jefftee
18th June 2015, 08:28
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.

mouni
19th June 2015, 06:43
plz give me example of QFuturewatcher

yeye_olive
19th June 2015, 11:10
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.

mouni
21st June 2015, 08:46
tell me how to move files from one folder to another folder

stampede
21st June 2015, 09:55
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

anda_skoa
21st June 2015, 11:18
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,
_

mouni
21st June 2015, 14:27
can you give example code

d_stranz
21st June 2015, 18:53
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.

mouni
22nd June 2015, 17:40
how can i declare windows move command in qt