Skip to content

KevinZ的小窝

Menu
  • Home
  • Categories
Menu

Linux中将文件夹下某前缀的文件进行文件名统计

Posted on 2024年 1月 18日 by KevinZhou
import os

# 获取当前目录中所有的.fastq.gz文件
file_names = [f for f in os.listdir('.') if f.endswith('.fastq.gz')]

# 使用字典存储分类
file_dict = {}

# 对文件名进行分类
for file in file_names:
    prefix = file.split('_')[0]
    if prefix in file_dict:
        file_dict[prefix].append(file)
    else:
        file_dict[prefix] = [file]

# 将结果写入文件
with open('sample_filenames.txt', 'w') as output_file:
    for prefix, files in file_dict.items():
        output_file.write(f"{prefix}\t{'; '.join(files)}\n")
2024 年 1 月
一 二 三 四 五 六 日
1234567
891011121314
15161718192021
22232425262728
293031  
« 11 月   6 月 »

俺家的猫~

胖达~

© 2026 KevinZ的小窝 |

粤ICP备2023017690号

|

粤公网安备 44010402003004号