Skip to content

Instantly share code, notes, and snippets.

@findix
Last active August 29, 2015 14:00
Show Gist options
  • Save findix/f41822e45b50edbacefe to your computer and use it in GitHub Desktop.
Save findix/f41822e45b50edbacefe to your computer and use it in GitHub Desktop.
自动识别文件类型修改拓展名
# -*- coding: utf-8 -*-
'''
author:凤翔
本工具可以根据文件头自动修改文件后缀名
'''
import os
# 设置目录
dir=u".\\ogg"
# 设置识别特征的文件头
filehead='Ogg'
# 设置想要修改的文件后缀名
filetype='ogg'
def RecType(rootDir):
list_dirs = os.walk(rootDir)
for root, dirs, files in list_dirs:
for f in files:
rawFile=open(os.path.join(root, f),'rb')
try:
head=rawFile.read(len(filehead))
if head==filehead:
print os.path.join(root, f)
rawFile.close()
except Exception, e:
raise e
finally:
rawFile.close()
RecType(dir)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment