pyfilesystem2 InvalidCharsInPath error when path contains square brackets [ & ]

249 Views Asked by At

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.

0

There are 0 best solutions below