0
0

file 抽出

Last updated at Posted at 2024-04-19
title.rb

import os
import csv

# 対象のディレクトリパスを設定
directory_path = 'D:/'

# 出力ファイル名
output_file = 'file_list.csv'

# 対象のディレクトリ内のファイルをリストアップ
file_names = []
for filename in os.listdir(directory_path):
    if filename.endswith('.csv'):
        # 拡張子 '.out' を除いたファイル名をリストに追加
        file_names.append(filename[:-4])

# CSVファイルに書き出し
with open(output_file, mode='w', newline='') as file:
    writer = csv.writer(file)
    for name in file_names:
        writer.writerow([name])  # CSVの各行にファイル名を出力

print(f"{len(file_names)} files found and listed in {output_file}.")

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