Creating File with Square Brackets in the name in Common Lisp in a MacBook creates problems. How can I do it?

I am trying to translate some Racket package for reading/writing xlsx files to Common Lisp and encountered a problem.
Excel files are nothing else than a bundle of xml files with strict specifications which are zipped.
Amongst them is a [Content_type].xml or [Content_Type].xml file.
Trying to generate and writing a file with square brackets in the name in the MacBook generates the error:

(defparameter *zip-xlsx-temp-directory* "test-directory/")
(defparameter *content-type-file* (merge-pathnames "[Content_Types].xml" *zip-xlsx-temp-directory*))
(with-open-file (stream (ensure-directories-exist *content-type-file-1*)
                        :direction :output
                        :if-does-not-exist :create
                        :if-exists :supersede)
  (format stream ""))

bad place for a wild pathname
   [Condition of type SB-INT:SIMPLE-FILE-ERROR]

Restarts:
 0: [RETRY] Retry SLY interactive evaluation request.
 1: [*ABORT] Return to SLY's top level.
 2: [ABORT] abort thread (#<THREAD tid=11295 "slynk-worker" RUNNING {70073BBFC3}>)

Backtrace:
 0: (SB-KERNEL::%FILE-ERROR #P"test-directory/[Content_Types].xml" "bad place for a wild pathname")
      Locals:
        ARGUMENTS = NIL
        DATUM = "bad place for a wild pathname"
        PATHNAME = #P"test-directory/[Content_Types].xml"
 1: (ENSURE-DIRECTORIES-EXIST #P"test-directory/[Content_Types].xml" :VERBOSE T :MODE 511)
      Locals:
        #:.DEFAULTING-TEMP. = T
        #:.DEFAULTING-TEMP.#1 = 511
        SB-IMPL::CREATED-P = NIL
        PATHNAME = #P"/Users/josephus/.roswell/local-projects/cl-simple-xlsx/tests/test-directory/[Content_Types].xml"
        SB-IMPL::PATHSPEC = #P"test-directory/[Content_Types].xml"
 2: ((LAMBDA ()))
 3: (SB-INT:SIMPLE-EVAL-IN-LEXENV (WITH-OPEN-FILE (STREAM (ENSURE-DIRECTORIES-EXIST *CONTENT-TYPE-FILE-1* :VERBOSE T) :DIRECTION :OUTPUT :IF-DOES-NOT-EXIST :CREATE ...) (FORMAT STREAM "")) #<NULL-LEXENV>)
 4: (EVAL (WITH-OPEN-FILE (STREAM (ENSURE-DIRECTORIES-EXIST *CONTENT-TYPE-FILE-1* :VERBOSE T) :DIRECTION :OUTPUT :IF-DOES-NOT-EXIST :CREATE ...) (FORMAT STREAM "")))
 5: ((LAMBDA NIL :IN SLYNK:INTERACTIVE-EVAL))
 6: (SLYNK::CALL-WITH-RETRY-RESTART "Retry SLY interactive evaluation request." #<FUNCTION (LAMBDA NIL :IN SLYNK:INTERACTIVE-EVAL) {70073E8F3B}>)
 7: (SLYNK::CALL-WITH-BUFFER-SYNTAX NIL NIL #<FUNCTION (LAMBDA NIL :IN SLYNK:INTERACTIVE-EVAL) {70073E8F1B}>)
 8: (SB-INT:SIMPLE-EVAL-IN-LEXENV (SLYNK:INTERACTIVE-EVAL "(with-open-file (stream (ensure-directories-exist *content-type-file-1* :verbose t) ..)
 9: (EVAL (SLYNK:INTERACTIVE-EVAL "(with-open-file (stream (ensure-directories-exist *content-type-file-1* :verbose t) ..)
10: (SLYNK:EVAL-FOR-EMACS (SLYNK:INTERACTIVE-EVAL "(with-open-file (stream (ensure-directories-exist *content-type-file-1* :verbose t) ..)
11: ((LAMBDA NIL :IN SLYNK::SPAWN-WORKER-THREAD))
12: (SLYNK-SBCL::CALL-WITH-BREAK-HOOK #<FUNCTION SLYNK:SLYNK-DEBUGGER-HOOK> #<FUNCTION (LAMBDA NIL :IN SLYNK::SPAWN-WORKER-THREAD) {70073E8C6B}>)
13: ((FLET SLYNK-BACKEND:CALL-WITH-DEBUGGER-HOOK :IN "/Users/josephus/.roswell/lisp/sly/git/slynk/backend/sbcl.lisp") #<FUNCTION SLYNK:SLYNK-DEBUGGER-HOOK> #<FUNCTION (LAMBDA NIL :IN SLYNK::SPAWN-WORKER-T..
14: ((LAMBDA NIL :IN SLYNK::CALL-WITH-LISTENER))
15: (SLYNK::CALL-WITH-BINDINGS ((*PACKAGE* . #<PACKAGE "CL-SIMPLE-XLSX/TESTS/MAIN">) (*DEFAULT-PATHNAME-DEFAULTS* . #P"/Users/josephus/.roswell/local-projects/cl-simple-xlsx/tests/") (* . #1="+01:00") (**..
16: ((LAMBDA NIL :IN SLYNK::SPAWN-WORKER-THREAD))
17: ((FLET SB-UNIX::BODY :IN SB-THREAD::RUN))
18: ((FLET "WITHOUT-INTERRUPTS-BODY-" :IN SB-THREAD::RUN))
19: ((FLET SB-UNIX::BODY :IN SB-THREAD::RUN))
20: ((FLET "WITHOUT-INTERRUPTS-BODY-" :IN SB-THREAD::RUN))
21: (SB-THREAD::RUN)

This seems to be a Lisp-immanent problem.

Taking my Python (in ipython zshell) and doing:

with open("[Content_Types].xml", "w") as f:
    f.write("<H1>Hi</H1>")

works without errors.

I tried (truename path) or escaping the brackets in the name “[Content_Types].xml” or “[Content_Types].xml” – if escaping the first one seems to be correct. But it didn’t help. Still getting the bad wildcard error.

After writing that, I tried to reproduce it in Linux (Ubuntu) and then consulted ChatGPT. Its initial answers (with using truename and escape the brackets were wrong).
So I think others might also struggle with this problem when asking ChatGPT directly.

The solution was:

If you must use filenames with brackets (e.g., [Content_Types].xml) in Common Lisp on macOS, it’s important to ensure that these brackets are handled correctly when working with file operations. Here’s how you can do it:

Handling Filenames with Brackets in Common Lisp:

1.  Use make-pathname to create pathnames:
This can avoid issues with special characters.
(defparameter *content-type-file*
  (make-pathname :directory content-dir :name "[Content_Types]" :type "xml"))
2.  Pass the pathname directly to with-open-file:
;; so I did first:
(defparameter *content-dir* "/Users/<your-user-name>/Downloads/test-zip/")
(ensure-directories-exist *content-dir*)
(defparameter *content-type-file*
  (make-pathname :directory *content-dir* :name "[Content_Types]" :type "xml"))

;; and then - step 2:
(with-open-file (stream *content-type-file*
                        :direction :output
                        :if-exists :supersede
                        :if-does-not-exist :create)
  (format stream "<H1/>"))

;; => NIL

And then it created correctly the file with the square brackets in the name.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật