Shammer's Philosophy

My private adversaria

Windows環境でFileIOを試す

Windows環境でwith-open-fileマクロを試してみた。確認したかったのは次の点。

  • Drive Letter はどういう扱いになるのか?
  • 作成されていないディレクトリは勝手に作ってくれるのか?エラーになるのか?

単純に、以下のように実行してみた。

? (with-open-file (f "C:/aaa/aaa.txt" :direction :output)
    (format f "Hello!"))
NIL
?

実行後、確認すると成功していた。ディレクトリを勝手に作成してくれるらしくありがたい。


probe-file も試してみたので念のためメモ。

? (probe-file "C:/Windows/System32/drivers/etc/hosts")
#P"C:/Windows/System32/drivers/etc/hosts"
? (probe-file "C:/foobarbaz")
NIL