Created
March 25, 2026 06:14
-
-
Save eyasuyuki/b4f06b70c4a0985479b96d83c3cca549 to your computer and use it in GitHub Desktop.
ファイルパスとディレクトリパスが混在するテキストファイルを読み込んでファイルパスだけ抽出する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| input_file = 'list.txt' | |
| output_file = 'files_only.txt' | |
| with open(input_file, 'r', encoding='utf-8') as f: | |
| paths = f.read().splitlines() | |
| # 実際にファイルとして存在するものだけを抽出 | |
| files_only = [p for p in paths if os.path.isfile(p)] | |
| with open(output_file, 'w', encoding='utf-8') as f: | |
| f.write('\n'.join(files_only)) | |
| print(f"完了: {len(files_only)} 個のファイルを抽出しました。") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment