用python实现了一个小型的自动发版本的工具。这个“自动发版本”有点虚, 只是简单地把debug 目录下的配置文件复制到指定目录,把Release下的生成文件复制到同一指定,过滤掉不需要的文件夹(.svn),然后再往这个指定目录添加几个特定的文件。

这个是我的第一个python小程序。

下面就来看其代码的实现。

首先插入必要的库:

 import os
import os.path
import shutil
import time, datetime

然后就是一大堆功能函数。第一个就是把某一目录下的所有文件复制到指定目录中:


 def copyFiles(sourceDir,  targetDir):
if sourceDir.find(".svn") >:
return
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
copyFiles(sourceFile, targetFile)

删除一级目录下的所有文件:

 def removeFileInFirstDir(targetDir):
for file in os.listdir(targetDir):
targetFile = os.path.join(targetDir, file)
if os.path.isfile(targetFile):
os.remove(targetFile)

复制一级目录下的所有文件到指定目录:


 def coverFiles(sourceDir,  targetDir):
for file in os.listdir(sourceDir):
sourceFile = os.path.join(sourceDir, file)
targetFile = os.path.join(targetDir, file)
#cover the files
if os.path.isfile(sourceFile):
open(targetFile, "wb").write(open(sourceFile, "rb").read())

复制指定文件到目录:

 def moveFileto(sourceDir,  targetDir):
shutil.copy(sourceDir, targetDir)

往指定目录写文本文件:

 def writeVersionInfo(targetDir):
open(targetDir, "wb").write("Revison:")

返回当前的日期,以便在创建指定目录的时候用:


 def getCurTime():
nowTime = time.localtime()
year = str(nowTime.tm_year)
month = str(nowTime.tm_mon)
if len(month) <:
month =''+ month
day = str(nowTime.tm_yday)
if len(day) <:
day =''+ day
return (year +'-'+ month +'-'+ day)

然后就是主函数的实现了:


 if  __name__ =="__main__":
print "Start(S) or Quilt(Q) \n"
flag = True
while (flag):
answer = raw_input()
if'Q'== answer:
flag = False
elif 'S'== answer :
formatTime = getCurTime()
targetFoldername ="Build "+ formatTime +"-01"
Target_File_Path += targetFoldername copyFiles(Debug_File_Path, Target_File_Path)
removeFileInFirstDir(Target_File_Path)
coverFiles(Release_File_Path, Target_File_Path)
moveFileto(Firebird_File_Path, Target_File_Path)
moveFileto(AssistantGui_File_Path, Target_File_Path)
writeVersionInfo(Target_File_Path+"\\ReadMe.txt")
print "all sucess"
else:
print "not the correct command"

感觉是果然简单, 不过简单的原因是因为库函数丰富,语言基本特性的简单真没感觉出来。

python 文件拷贝的更多相关文章

  1. windows python文件拷贝到linux上执行问题

    之前在Windows下写好了一个Python脚本,运行没问题,今天在Linux下,脚本开头的注释行已经指明了解释器的路径,也用chmod给了执行权限,但就是不能直接运行脚本. 1 问题1: 报错:: ...

  2. windows python文件拷贝到linux上执行问题-换行符问题/r/n

    之前在Windows下写好了一个Python脚本,运行没问题,今天在Linux下,脚本开头的注释行已经指明了解释器的路径,也用chmod给了执行权限,但就是不能直接运行脚本. 1 问题1: 报错:: ...

  3. python 简单实现文件拷贝

    1.背景 一日加班需要写一个文件拷贝的函数. 写了几版拷贝函数,有需要的直接粘贴过去 def CopyLocaleFile1(sorfile,desfile): #第一版 sorfp=open(sor ...

  4. python批量拷贝文件

    普通批量拷贝文件 import os import shutil import logging from logging import handlers from colorama import Fo ...

  5. Python:tarxjb简单、安全文件拷贝、传输

    tarxjb 简单.安全文件拷贝.传输 描述 通过python paramiko库实现简易ssh.sftp执行操作,从而实现文件的远程传输 Github 优点: 可靠传输,文件不易受损 安全传输,避免 ...

  6. python文件处理-根据txt列表将文件从其他文件夹 拷贝到指定目录

    内容涉及:路径拼接,文件拷贝,内容追加(append) # !/usr/bin/python # -*- coding: UTF-8 -*- import pandas as pd import os ...

  7. Python 文件操作函数

    这个博客是 Building powerful image classification models using very little data 的前期准备,用于把图片数据按照教程指示放到规定的文 ...

  8. linux或者windows下的文件拷贝

    #  上代码 #!/usr/bin/env python # -*- coding:utf-8 -*- import os import shutil import tarfile base_dir ...

  9. python文件和元组

    python文件操作 相较于java,Python里的文件操作简单了很多 python 获取当前文件所在的文件夹: os.path.dirname(__file__) 写了一个工具类,用来在当前文件夹 ...

随机推荐

  1. Flume1.5.0的安装、部署、简单应用(含伪分布式、与hadoop2.2.0、hbase0.96的案例)

    目录: 一.什么是Flume? 1)flume的特点 2)flume的可靠性 3)flume的可恢复性 4)flume 的 一些核心概念 二.flume的官方网站在哪里? 三.在哪里下载? 四.如何安 ...

  2. HOG matlab练习

    matlab练习程序(HOG方向梯度直方图) HOG(Histogram of Oriented Gradient)方向梯度直方图,主要用来提取图像特征,最常用的是结合svm进行行人检测. 算法流程图 ...

  3. 关于动态生成data组件

    /*! * WeX5 v3 (http://www.justep.com) * Copyright 2015 Justep, Inc. * Licensed under Apache License, ...

  4. 【uTenux实验】中断处理

    中断处理是一个比较有意思的东西.uTenux的中断处理包括了处理外部中断.CPU异常等.他是OS中任务无关部分.因此,当中断到来的时候OS会停止任务调度,不会发生任务切换.直到程序从中断中返回. uT ...

  5. 链地址法实现HashMap

    前注:本文介绍的HashMap并非Java类库的实现.而是根据哈希表知识的一个实现. 上文介绍了开放地址法实现HashTable,它的缺点是对hashCode映射为地址后如果出现重复地址,则会占用其他 ...

  6. mysql登录基本语句

    默认密码:root mysql 显示所有的数据库,代码如下: mysql> show databases; mysql> show tables; MySQL显示命令二.显示命令 1.显示 ...

  7. NBU恢复报:ORA-19554 ORA-27211

    RMAN> run {2> allocate channel ch00 type 'sbt_tape' parms='ENV=(NB_ORA_CLIENT=rac1)';3> res ...

  8. Esfog_UnityShader教程_镜面反射SpecularReflection

    系列教程第四篇,本来打算昨天写的,有些小偷懒就今天写了,这一期我们来讨论一下关于镜面反射的基本原理和具体代码.这一篇是承接着上一篇<Esfog_UnityShader教程_漫反射DiffuseR ...

  9. R&S学习笔记(一)

    1.一个VRF有两个主要的组成部分:路由区分符RD和路由目标RT.一个路由区分符(RD)是一个数字,除了帮助识别在一个提供商的网络中的VPN和允许重叠 IP区域之外没有其它的含义.RD是一个分为两个部 ...

  10. Installing Erlang

    Installing Erlang Pre-built binaries for most common platforms. Source code releases from the main E ...