Skip to content

Instantly share code, notes, and snippets.

@mintisan
Last active June 25, 2016 06:38
Show Gist options
  • Save mintisan/de3c84866a4903b4b8e9d166a8c92fd3 to your computer and use it in GitHub Desktop.
Save mintisan/de3c84866a4903b4b8e9d166a8c92fd3 to your computer and use it in GitHub Desktop.
add a specific prefix for all files within current directory
#-*- coding: utf-8 -*-
import os
import numpy as np
import walkdir as wd
prefix = 'pre-'
file_info_type = np.dtype({
'names': ['dir','name'],
'formats':['S100','S100']
})
# 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 + '\\' + prefix + f
#print old, new
os.rename(old,new)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment