python 关于文件的一些操作
来源:互联网 发布:海量数据上市 编辑:程序博客网 时间:2024/04/30 04:48
#! /usr/bin/python
# -*- coding:utf-8 -*-
'''
Created on 2013-12-11
@author: Java
'''
import os
import MySQLdb
from db.DbUtil import DbUtil
class FileOption():
def __init__(self):
pass
def CreateFloderByList(self,pathList):
'''
创建文件夹
:param pathList:文件夹集合
'''
self.pathList = pathList
for path in pathList:
if not os.path.isdir(path):
os.makedirs(path)
self.path = path
if not os.path.isdir(path):
os.makedirs(path)
def readFileName(self,path):
fileNames = os.listdir(path)
return fileNames
def copyFiles(self,sourceDir, targetDir):
for file in os.listdir(sourceDir):
sourceFile = os.path.join(sourceDir, file)
targetFile = os.path.join(targetDir, file)
if os.path.isfile(sourceFile):
if not os.path.exists(targetDir):
os.makedirs(targetDir)
if not os.path.exists(targetFile) or(os.path.exists(targetFile) and (os.path.getsize(targetFile) != os.path.getsize(sourceFile))):
open(targetFile, "wb").write(open(sourceFile, "rb").read())
if os.path.isdir(sourceFile):
First_Directory = False
create = FileOption()
create.copyFiles(sourceFile, targetFile)
def moveFiles(self,dir):
'''根据文件名创建文件夹,并将其放入对应的文件夹内'''
for i in os.listdir(dir):
name = ''.join(i.split('.html')[0:-1])
print name
os.mkdir(os.path.join(dir,name))
os.rename(os.path.join(dir,i), os.path.join(dir,name,i))
# -*- coding:utf-8 -*-
'''
Created on 2013-12-11
@author: Java
'''
import os
import MySQLdb
from db.DbUtil import DbUtil
class FileOption():
def __init__(self):
pass
def CreateFloderByList(self,pathList):
'''
创建文件夹
:param pathList:文件夹集合
'''
self.pathList = pathList
for path in pathList:
if not os.path.isdir(path):
os.makedirs(path)
def CreateFloder(self,path):
self.path = path
if not os.path.isdir(path):
os.makedirs(path)
def readFileName(self,path):
fileNames = os.listdir(path)
return fileNames
def copyFiles(self,sourceDir, targetDir):
for file in os.listdir(sourceDir):
sourceFile = os.path.join(sourceDir, file)
targetFile = os.path.join(targetDir, file)
if os.path.isfile(sourceFile):
if not os.path.exists(targetDir):
os.makedirs(targetDir)
if not os.path.exists(targetFile) or(os.path.exists(targetFile) and (os.path.getsize(targetFile) != os.path.getsize(sourceFile))):
open(targetFile, "wb").write(open(sourceFile, "rb").read())
if os.path.isdir(sourceFile):
First_Directory = False
create = FileOption()
create.copyFiles(sourceFile, targetFile)
def moveFiles(self,dir):
'''根据文件名创建文件夹,并将其放入对应的文件夹内'''
for i in os.listdir(dir):
name = ''.join(i.split('.html')[0:-1])
print name
os.mkdir(os.path.join(dir,name))
os.rename(os.path.join(dir,i), os.path.join(dir,name,i))
0 0
- python 关于文件的一些操作
- 关于文件的一些操作
- python关于文件的操作
- 关于Python的文件操作
- 关于python的文件操作
- Python关于文件的操作
- 轻松python之文件专题-关于zip文件的一些操作
- Python文件及文件夹的一些操作
- python对文件,文件夹的一些操作
- vba 关于文件的一些操作
- PHP关于文件的一些基本操作
- 关于目录、文件的一些操作
- python 关于文件的一些方法
- 轻松python之文件专题-关于目录树的一些操作
- 关于python文件操作
- 关于python文件操作
- 关于python文件操作
- 关于python文件操作
- ubuntu10.04编译android4.0.3的要点
- NSCharacterset 和NSString
- 缺陷管理工具 ALM -- Change Request
- Java中Annotation(注释)系列学习笔记(2)
- C#程序删除自身
- python 关于文件的一些操作
- RHEL_6.0 GCC安装
- android -- WatchDog看门狗分析
- Install the Legato Networker client on Solaris 10
- Oracle SQL trace 不同level 的区别
- 类的特殊用法(一)定义
- Java中Annotation(注释)系列学习笔记(3)
- Linux下gcc编译控制动态库导出函数小结 .
- 修改boot.img文件的工具,mkbootfs,mkbootimg,unpackbootimg