LoginSignup
0
1

More than 1 year has passed since last update.

簡単な業務改善ツールを作ってみた

Posted at

作ろうと思ったきっかけ

日々の業務に圧殺されないために簡易ツールを作りました。

このツールで出来ること

特定の名称で新規にフォルダを作成。
作成したフォルダ配下にエクセルファイルを配置。

言語バージョン

C:\Users\test>python --version
Python 3.8.10

実装

def make_folder(file_path):
    file_dir_path = os.path.dirname(file_path)
    file_name = os.path.basename(file_path)
    dir_name = "【新規フォルダ】" + file_name
    file_dir_path = "\\Users\\test\\デスクトップ\\新規フォルダ作成/" + dir_name
    os.mkdir(file_dir_path)
    # make file_path
    new_file_path = file_dir_path + '/' + file_name    
    # copy
    shutil.copyfile(file_path, new_file_path)

def arrange_file_path():
    file_path = text_box.get("1.0","end")
    file_path = file_path.replace('"','')
    file_path = file_path.replace('\\', '/')
    file_path = file_path[:-1]  
    # makelist
    arrange_file_path = []
    arrange_file_path = file_path.split('\n')
    return arrange_file_path

def get_text():
    files = arrange_file_path()
    for file_path in files:
        make_folder(file_path)

# set Frame
root = tk.Tk()
root.geometry("500x200")

# make component
text_box = tk.Text()
text_box["width"] = 80
text_box["height"] = 13
button = tk.Button()
button["text"] = "Button"
button["command"] = get_text

#set component
text_box.pack()
button.pack()

# set focus
text_box.focus_set()

root.mainloop()

◇詳細

コピー元のファイルを張り付けるため、テキストエリアの枠とボタンを作成しています。

# set Frame
root = tk.Tk()
root.geometry("500x200")

# make component
text_box = tk.Text()
text_box["width"] = 80
text_box["height"] = 13
button = tk.Button()
button["text"] = "Button"
button["command"] = get_text

#set component
text_box.pack()
button.pack()

# set focus
text_box.focus_set()

root.mainloop()

def get_text():

枠内に入りつけたファイルパスを取得しています。

def get_text():
    files = arrange_file_path()
    for file_path in files:
        make_folder(file_path)

def arrange_file_path():

ファイルの配置とフォルダ作成用に、取得したファイルパスを成型しています。
また、複数ファイルを取得したとき用にリストへファイルパスを格納しています。

def arrange_file_path():
    file_path = text_box.get("1.0","end")
    file_path = file_path.replace('"','')
    file_path = file_path.replace('\\', '/')
    file_path = file_path[:-1]  
    # makelist
    arrange_file_path = []
    arrange_file_path = file_path.split('\n')
    return arrange_file_path

def make_folder(file_path):

取得したファイルパスの名称に変更を加え、新しくフォルダを作成しています。
また、作成したフォルダ配下にファイルをコピーして配置しています。

def make_folder(file_path):
    file_dir_path = os.path.dirname(file_path)
    file_name = os.path.basename(file_path)
    dir_name = "【新規フォルダ】" + file_name
    file_dir_path = "\\Users\\test\\デスクトップ\\新規フォルダ作成/" + dir_name
    os.mkdir(file_dir_path)
    # make file_path
    new_file_path = file_dir_path + '/' + file_name    
    # copy
    shutil.copyfile(file_path, new_file_path)

◇感想

フォルダの作成・エクセルファイルの配置だけですが、
5秒ですら惜しい瞬間に使えるため常用しています。

ご覧いただきありがとうございました。

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