LoginSignup
0
1

More than 3 years have passed since last update.

Pythonメモ① フォルダ,ファイルの操作

Posted at

pythonによるファイル、フォルダの基本操作

自分用メモです。バージョンはpython3.7.1です。随時追記します。

フォルダの作成

make_folder.py
# make folder
import os

def make_folder(path):
  if os.path.exists(path)==False:
    os.mkdir(path)

 ファイルのみ取得する

get_files.py
import os
import sys

def get_images(path):
  folder = os.listdir(path):
  files = [f for f in folder if os.path.isfile(os.path.join(path, f))]
  if len(files)==0:
    print("File does not exist")
    sys.exit()
  return files

 ファイルの名前と拡張子を取得

get_filename.py

name, ext =  os.path.splitext(file)
0
1
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
1