Created
October 21, 2016 02:24
-
-
Save arischow/a08b1f2701e15d0ce2c87d6e53a2fd82 to your computer and use it in GitHub Desktop.
获取某目录下的所有同类型文件
This file contains 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 | |
import fnmatch | |
matches = [] | |
for root, dirs, files in os.walk('/Users/arischow/Desktop/data'): | |
for file in fnmatch.filter(files, '*.txt'): | |
matches.append(os.path.join(root, file)) | |
print(matches) | |
for match in matches: | |
with open(match, 'r', encoding='utf8') as original_file: | |
with open('/Users/arischow/Desktop/data/numberOnly.txt', 'a') as new_file: | |
for line in original_file: | |
line = line.split(',')[-1] | |
new_file.write(line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment