该函数返回path路径下的文件名称列表(不是文件全路径),包括文件夹名称
import os
path="E:\\Ct\\src"
targetDir="E:\\target"
def CopyAllDir(source,target):
for file in os.listdir(source):
sourceFile = os.path.join(source,file)
targetFile = os.path.join(target,file)
if os.path.isfile(sourceFile):
if not os.path.exists(target):
os.makedirs(target)
open(targetFile, "wb").write(open(sourceFile, "rb").read())
if os.path.isdir(sourceFile):
CopyAllDir(sourceFile,targetFile)
CopyAllDir(path,targetDir)
遍历文件列表返回一个元组,元组内容为(dirpath, dirnames, filenames)
def getpathlist(path):
pathlist = []
for root, _, files in os.walk(path, followlinks=True):
for f in files:
if f.endswith('.lua'):
fullpath = os.path.join(root, f)
fullpath = fullpath.replace("\\", "/")
pathlist.append(fullpath)
return pathlist