Created
July 13, 2016 14:12
-
-
Save absentm/4923480560554ab87af611049a1cef14 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
# coding: utf-8 | |
import os | |
import shutil | |
import sys | |
# get the filename without extra extend name | |
def getImageFilePre(filename): | |
if filename.endswith(".png"): | |
temp = filename.split(".") | |
filePre = temp[0] | |
return filePre | |
# string 转 int | |
def str2Int(stringValue): | |
return int(stringValue) | |
# int 转 string | |
def int2Str(intValue): | |
return str(intValue) | |
# file rename | |
def fileRename(dirPath): | |
# three params: | |
# 1.parent catalog | |
# 2.all the catalogs' name | |
# 3.all the file names | |
for parent, dirnames, filenames in os.walk(dirPath): | |
for dirname in dirnames: | |
count = 1 | |
newTmpPath = os.path.join(dirPath, dirname) | |
os.chdir(newTmpPath) | |
fileContents = os.listdir(newTmpPath) | |
for curFile in fileContents: | |
if curFile.endswith(".png"): | |
newName = dirname + "."+ int2Str(count) + ".png" | |
count = count + 1 | |
shutil.move(curFile, newName) | |
print curFile + " -> " + newName + " ------> OK!" | |
def main(): | |
rootPath = "~\\data_origin\\train_with_class" | |
fileRename(rootPath) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment