QFileSystemWatcher - file renaming, what is your new name?
-
hello,
QFileSystemWatcher can tell me that a file was renamed, but how do I know which is your new name?
thank you very much,
regards,
-
Hi,
The signal provides all the information you need:
@void QFileSystemModel::fileRenamed(const QString & path, const QString & oldName, const QString & newName)@
-
QFileSystemWatcher won't tell you that kind of information.
You can store a list of known files or directory contents and guess as to what changed by comparing the updated list to the last known contents. I wouldn't rely on this though as there are many reasons why directory contents may change.
The proper way to do this would be to use the internal system file name and attach to this. In GNU/Linux you would use something like 'inotify' to do this which would respond back when any change occurred (including renaming or moving a file).
I know OS X can do this as well. My favorite text editor can immediately recognize when a file is renamed or even moved to the trash (it follows it) so I know the capability is there.
I don't know what Windows can do. I have never seen any Windows application that can track a file when it is renamed or moved. It may not be able to do this.
When you rename a watched file QFileSystemWatcher will remove the file from the watched list so I don't think it monitors anything other then the file name (?).
-
Thank you very much SGaist,
I notice that QFileSystemModel uses QFileSystemWatcher for homework, this can take a lot of resources because I use QFileSystemWatcher to monitor changes and deletions and QFileSystemModel for renames? would not redundant?
I say this thinking that for each file to be monitored must create an instance of QFileSystemModel to monitor renames, if the monitor files are in different directories, this what I can not control because the user is going to be the one to decide how many files will be open
Thank you very much,
regards,
-
First thing, sorry, I misread the title.
I wouldn't create a QFileSystemModel per file, that wouldn't do any good. However it might be a good alternative to watch a folder in your case
-
In Windows, ReadDirectoryChangesW() can watch for folder content changes:
The names of the dirs / files that have been created / deleted / modified.
Both the old and new names of the dir / file in the case of renaming.