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?

ディレクリーツリーの可視化

Posted at
import os
import streamlit as st

def save_file_list_to_txt(folder_path, output_path="file_list.txt"):
    """指定されたフォルダのファイルリストを.txtに保存"""
    try:
        with open(output_path, "w") as f:
            for dirpath, dirnames, filenames in os.walk(folder_path):
                depth = dirpath.replace(folder_path, "").count(os.sep)
                indent = "    " * depth
                f.write(f"{indent}└── {os.path.basename(dirpath)}/\n")
                for filename in filenames:
                    f.write(f"{indent}    ├── {filename}\n")
        return output_path
    except Exception as e:
        st.error(f"エラーが発生しました: {e}")
        return None

st.title("フォルダのファイルリストを保存")

# フォルダパスの入力
folder_path = st.text_input("フォルダのパスを入力してください:")

if folder_path:
    if st.button("ファイルリストを保存"):
        output_file = save_file_list_to_txt(folder_path)
        if output_file:
            st.success(f"ファイルリストを '{output_file}' に保存しました。")
            with open(output_file, "rb") as file:
                st.download_button(
                    label="ダウンロード",
                    data=file,
                    file_name="file_list.txt",
                    mime="text/plain",
                )


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?