Skip to content

Instantly share code, notes, and snippets.

@mintisan
Created June 25, 2016 06:39
Show Gist options
  • Save mintisan/bc1f95364259c0f23e3db880957a48c9 to your computer and use it in GitHub Desktop.
Save mintisan/bc1f95364259c0f23e3db880957a48c9 to your computer and use it in GitHub Desktop.
modify split in file_name
#-*- 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_split = '-'
new_split = '_'
# 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_split, new_split)
os.rename(old,new)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment