[python-win32] file name contains brackets got converted to %5B and %5D

Steven Manross steven at manross.net
Mon Apr 11 11:55:32 EDT 2022


After thinking about this for a bit …  I thought that if the COM object is doing this and there’s no way to fix that behavior, you should be able to change the file name AFTER the COM object is done, via python like so.

# this works on my W10 PC
import os

# make sure the file handle and or COM object is done locking the DOCX file first

os.rename('c:\\somedir\\this%5Bproject_id%5D_date.docx', 'c:\\somedir\\this[project_id]_date.docx')


Obviously, if the escaping works like Chris suggests, you wouldn’t need this.

HTH

Steven
From: python-win32 <python-win32-bounces+steven=manross.net at python.org> On Behalf Of Christoph J. Dorner
Sent: Saturday, April 09, 2022 2:52 AM
To: jefferyliao at actgenomics.com; python-win32 at python.org
Subject: Re: [python-win32] file name contains brackets got converted to %5B and %5D

Hi,

I am not sure If I gto the context, it is hard to understand what you have done witht he limited description.

But I guess you passed a filename to a COM object ?
Try to escape the brackets.
And check for problems arising a) from the different notation conventions for pathnames and b) differences in unicode treatment in Python an COM.

Regards
Christoph


Am 08.04.2022 um 04:11 schrieb Jeffery Liao (廖弈全):
Hi,

My docx file name contains brackets ([ and ]) and those brackets were changed to %5B and %5D after I convert the docx to pdf.

e.g.
before: name_[project_id]_date.docx

after: name_%5Bproject_id%5D_date.pdf

I've searched Document.ExportAsFixedFormat<https://docs.microsoft.com/en-us/office/vba/api/word.document.exportasfixedformat> method (Word) and didn't find any option to change this behavior.

Is there any way to keep the brackets in file name?

Version of Python and pywin32:
Python v3.8.10, pywin32 v300

Best regards
Jeffery


This message contains confidential information and is intended only for the individual(s) addressed in the message. If you aren't the named addressee, you should not disseminate, distribute, or copy this e-mail. If you aren't the intended recipient, you are notified that disclosing, distributing, or copying this e-mail is strictly prohibited.
ACT Genomics Holdings Co. Ltd. and its subsidiaries<https://www.actgenomics.com/en>



_______________________________________________

python-win32 mailing list

python-win32 at python.org<mailto:python-win32 at python.org>

https://mail.python.org/mailman/listinfo/python-win32

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/python-win32/attachments/20220411/7fb32292/attachment.html>


More information about the python-win32 mailing list