0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

はじめに

移植やってます

os.path.splitext (Python)

import os

print(os.path.splitext("/C/Users/users/Documents/text.txt"))
print(os.path.splitext("C:\\Users\\users\\Documents\\text.txt"))

# ('/C/Users/users/Documents/text', '.txt')
# ('C:\\Users\\users\\Documents\\text', '.txt')

拡張子の切り分けです。
正規表現でやってもいいと思いますが。 ファイルを変換するして保存する際に使用されます。

Pathname#sub_ext (Ruby)

require "pathname"

p1 = Pathname("/C/Users/users/Documents/text.txt")
p2 = Pathname("C:\\Users\\users\\Documents\\text.txt")

puts "#{p1.sub_ext('')} #{p1.extname}"
puts "#{p2.sub_ext('')} #{p2.extname}"
puts p2.sub_ext('.xml')

# /C/Users/users/Documents/text .txt
# C:\Users\users\Documents\text .txt
# C:\Users\users\Documents\text.xml

メモ

  • Python の os.path.splitext を学習した
  • 道のりは遠そう
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?