2

I'm using pyfilesystem2 to scan for files in my network and deleting those that shouldn't be there. The problem comes when the file I'm trying to delete contains square brackets [ & ], ex: 'Operation Red Sea (Hong hai xing dong) (2018) [VOSE].mpg'

I've tried without success to escape the brackets, using [ and \x5B

I'm using fs.version=='2.4.11' python 3.8.5 running on Linux

sample code:

import fs
f = fs.open_fs(f"smb://myuser:mypass@myserver/D$")
f.remove('departamentos/d/FACTORES/Filmes/Operation Red Sea (Hong hai xing dong) (2018) [VOSE].sh')

output:

Traceback (most recent call last):
  File "/usr/lib/python3.8/code.py", line 90, in runcode
    exec(code, self.locals)
  File "<input>", line 1, in <module>
  File "/usr/local/lib/python3.8/dist-packages/fs/wrapfs.py", line 204, in remove
    _fs.remove(_path)
  File "/usr/local/lib/python3.8/dist-packages/fs/smbfs/smbfs.py", line 405, in remove
    _path = self.validatepath(path)
  File "/usr/local/lib/python3.8/dist-packages/fs/base.py", line 1489, in validatepath
    raise errors.InvalidCharsInPath(path)
fs.errors.InvalidCharsInPath: path 'departamentos/d/FACTORES/Filmes/Operation Red Sea (Hong hai xing dong) (2018) [VOSE].sh' contains invalid characters

I tested removing characters from the name and the code works right after removing both square brackets from the filename.

  • Please include a stack trace. If we need to look up the pyfilesystem2 code to answer this question, you should include enough information that we know exactly which file to look in. – Charles Duffy Apr 27 '21 at 15:35
  • _In general_, it's a bug if you need to do any escaping as an API user. Filenames should always be literal, matching exactly what's going to be passed to the underlying syscalls. Thus, this could well be a situation where the right answer is "pyfilesystem2 is broken, go talk to its author/maintainer"; indeed, that might not be a bad place to start regardless. – Charles Duffy Apr 27 '21 at 15:36
  • Also, a [mre] would tell us which exact pyfilesystem2 modules/plugins/backends you're using. We might be able to figure out the most relevant ones from the stack trace, but either way it's necessary information. – Charles Duffy Apr 27 '21 at 15:38

0 Answers0