ããã£ãã®ã§å¾å¦ã®ããã«ã¡ã¢ãæ®ãã¦ãã¾ãããããã
ä¸æçã«ãã¡ã¤ã«ã·ã¹ãã ã«ãã¡ã¤ã«ããã£ã¬ã¯ããªãä½ããããã¨ãããã¨ã¯ããããããã ãé©å½ãªååã§ä½æããã¨ååã被ã£ã¦äºæ
ã®å
ã«ãªã£ã¦ãã¾ãããã®ãããåããã°ã©ãã³ã°è¨èªã«ã¯ä¸æãã¡ã¤ã«ã»ãã£ã¬ã¯ããªãä½æããå°ç¨ã®APIãç¨æããã¦ãããã¨ãå¤ã(libcã«mktemp(3)
ãç¨æããã¦ãããããæçµçã«ãããå¼ã³åºãã¦ããã®ã§ã¯ãªãã)ã
Node.jsã®fs
ã¢ã¸ã¥ã¼ã«ããã®æ©è½ãæä¾ãã¦ããã®ã ããprefix
ãæå®ããã¨ã以ä¸ã®ç¹ã«æ³¨æããå¿
è¦ãããã
prefix
ã«ã¯/tmp/
ãå«ããå¿ è¦ããã
ã¤ã¾ã以ä¸ã®ããã«ä½¿ãå¿ è¦ãããã¨ãããã¨:
import fs from 'fs'; const tempFile = fs.mkdtempSync('/tmp/foobar-'); // => /tmp/foobarABCDEF // ... fs.rmdirSync(tempFile);
以ä¸ã®ããã«æ¸ãã¨æ¨©éä¸è¶³ã§ã³ã±ã(æå³ããªãå ´æã«æ¸ãè¾¼ããã¨ãã¦ãã¾ã)
import fs from 'fs'; const tempFile = fs.mkdtempSync('foobar-'); // => Error: EACCES: permission denied, mkdtemp 'foobar-XXXXXX' // ... fs.rmdirSync(tempFile);
ä¸è¦ã¨ã©ã¼æã«ã©ãã«æ¸ãè¾¼ããã¨ãããåãããªãã®ã§æ³¨æãå¿ è¦ã ã
ãªãã§ãããªAPIã«ãããã ã!!!!!
ä»ã®è¨èªã ã¨ã©ããªã£ã¦ãã®
Scalaã®os-lib
ã ã¨prefix
æå®ã«/tmp
ãå«ããå¿
è¦ã¯ãªã:
//> using scala 3.3.1 //> using toolkit latest val tmp = os.temp.dir(prefix = "mktemp-") println(tmp) // => /tmp/mktemp-8415820769307691913
Rubyã§ãprefix
æå®ã¨ãã£ã¬ã¯ããªã¯åé¢ããã¦ãã:
require 'tmpdir' Dir.mktmpdir("foo"){|dir| puts dir # => /tmp/foo20231226-1057143-rj7zc }
Pythonã§ãåæ§:
import tempfile import os with tempfile.TemporaryDirectory(prefix="foobar") as dname: print(dname) # => /tmp/foobar9y6ri4j3
Goã§ã¯ãã£ã¬ã¯ããªæå®ã空æååã«ããã¨èªåçã«/tmp
ãªã©ãå©ç¨ããã:
package main import ( "log" "os" "path/filepath" ) func main() { dir, err := os.MkdirTemp("", "example") // => /tmp/example123456 if err != nil { log.Fatal(err) } defer os.RemoveAll(dir) // clean up }
Rustã«ã¯mktemp
ã¨ããcrateãããããprefixæå®ã¯ã§ããªããã
ã¾ã¨ã
Nodeã®APIã ããªããå¥å¦ãªãã¨ã«ãªã£ã¦ããã®ã§æ°ãã¤ãã¦ã