Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File events inside a folder will only work with wxFileSystemWatcher if the folder path has a trailing slash #17277

Open
wxtrac opened this issue Dec 4, 2015 · 5 comments

Comments

@wxtrac
Copy link
Collaborator

wxtrac commented Dec 4, 2015

Issue migrated from trac ticket # 17277

component: wxX11 | priority: normal

2015-12-04 19:01:01: halfer created the issue


I recently implemented a wxFileSystemWatcher (wxphp/wxphp#113) in wxPHP, and found an interesting thing. To monitor what happens inside a folder with add(), the directory needs to have a trailing slash. I've found that without the slash, events are received OK but filenames of created/deleted files are not included in the notification.

The maintainer of wxPHP doesn't seem to think this behaviour is introduced on the PHP side, so we wonder if it might be introduced upstream? If so, is this deliberate?

This occurs with wxPHP built against 3.0.2 of wxWidgets.

I'd be more than happy to run any wxPHP tests if it is helpful.

@wxtrac
Copy link
Collaborator Author

wxtrac commented Dec 4, 2015

2015-12-04 19:03:56: halfer commented


I have tested this behaviour on GNU/Linux Ubuntu 14.04, PHP 5.5.9-1ubuntu4.14.

@cilynx
Copy link

cilynx commented Apr 15, 2022

Confirmed same behavior with wxPython on Linux.

This works as you would expect with event.Path and event.NewPath containing the full path to the changed files.

    def CreateFileSystemWatcher(self):
        self._fswatcher = wx.FileSystemWatcher()
        self._fswatcher.Bind(wx.EVT_FSWATCHER, self.OnFSEvent)
        self.inbox = os.path.join(self.library.dir, 'inbox/')
        os.makedirs(self.inbox, exist_ok=True)
        self._fswatcher.Add(self.inbox)

This still fires events, but event.Path and event.NewPath are always just the full path to the inbox directory with no information about the files changed.

    def CreateFileSystemWatcher(self):
        self._fswatcher = wx.FileSystemWatcher()
        self._fswatcher.Bind(wx.EVT_FSWATCHER, self.OnFSEvent)
        self.inbox = os.path.join(self.library.dir, 'inbox')
        os.makedirs(self.inbox, exist_ok=True)
        self._fswatcher.Add(self.inbox)

There's a Google Groups thread for 2013 confirming the same behavior on wxPython MSW as well.
https://groups.google.com/g/wxpython-users/c/YMSXZ01BHHQ/m/gHSpRMAxe1UJ

@vadz
Copy link
Contributor

vadz commented Apr 15, 2022

Is inbox a file or a directory?

@cilynx
Copy link

cilynx commented Apr 15, 2022

In my case, inbox is a directory that I drop files into for my app to process. The more I stare at this, the more it feels it might be deliberate behavior. I don't know if wxFileSystemWatcher under the hood can determine if a watched path is a file or directory without looking for the trailing slash. If not, the answer might just be a quick note in the docs to make sure you include the trailing os.sep if you need to receive the filenames under your watched directory in the events.

@PBfordev
Copy link
Contributor

I believe that generally, when working with paths in wxWidgets (e.g., using wxFileName) where the path is provided as a single string and the path is a folder, it is needed to denote that with a trailing path separator, otherwise the path is treated as a file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants