Created
June 25, 2016 07:04
-
-
Save mintisan/863d2714e3111bf9dab4f010b5e56fa5 to your computer and use it in GitHub Desktop.
modify file's suffix
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
#-*- coding: utf-8 -*- | |
import os | |
import numpy as np | |
import walkdir as wd | |
file_info_type = np.dtype({ | |
'names': ['dir','name'], | |
'formats':['S100','S100'] | |
}) | |
old_suffix = 'csv' | |
new_suffix = 'txt' | |
# 0. get all file list | |
files = list(wd.file_paths(wd.filtered_walk(os.getcwd(),depth=1,included_files=['*.csv']))) | |
# 1. split dir & file | |
for x in xrange(0,len(files)): | |
s = '\\' | |
p = unicode(s.join(files[x].split('\\')[:-1]), 'gbk') | |
f = files[x].split('\\')[-1] | |
print p, f | |
old = p + '\\' + f | |
new = p + '\\' + f.replace(old_suffix, new_suffix) | |
os.rename(old,new) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment