用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. Ubuntu 系统密码相关问题

    第一个问题: Ubuntu 密码失效解决办法 拷贝:http://www.myexception.cn/operating-system/1707766.html ubuntu14.04突然不能登录, ...

  2. libcurl发起post请求时间延迟问题。except为空即可

    最近在做团购酒店APP分享到qzone功能,使用libcurl访问qzone的分享cgi接口,酒店分享信息以POST方式传输,在测试的时候发现分享接口平均有2s的延迟,这延迟也太大了吧,于是乎问了空间 ...

  3. PDO多种方式取得查询结果

    PDO多种方式取得查询结果 01 December 2009 1:26 Tuesday by Sjolzy PDO最大的特点之一是它的灵活性,本节将介绍如何取得查询结果,包括: 数组(数值或关联数组) ...

  4. Tcpdump非常实用的抓包12实例

    1.过滤主机---------------------------------------------------------------- - 抓取所有经过 eth1,目的或源地址是 192.168 ...

  5. IOCP之客户端及消息传递

    上篇说到IOCP的精简实现,这篇来讲IOCP客户端和消息传递 在ConnectEx代码之前,CreateIoCompletionPort的第三个参数,把socket句柄+0x01000000作为传递 ...

  6. ios crash 日志分析

    以下内容来自网络 https://coderwall.com/p/ezdcmg/symbolicating-an-ios-crash-log-without-the-original-dsym-fil ...

  7. Eclipse 配置Activiti插件

    Eclipse 配置Activiti插件 我使用的是Eclipse LUNA 4.4.0 点击Eclipse上方工具栏[Help]选择[Install New Software] 在弹出的窗口点击[A ...

  8. Codeforces 719E [斐波那契区间操作][矩阵快速幂][线段树区间更新]

    /* 题意:给定一个长度为n的序列a. 两种操作: 1.给定区间l r 加上某个数x. 2.查询区间l r sigma(fib(ai)) fib代表斐波那契数列. 思路: 1.矩阵操作,由矩阵快速幂求 ...

  9. host DNS 访问规则

    昨天站点一直出现302循环重定向问题,捣鼓了半天才解决,原来是hosts和dns配置问题. 注:当你的站点出现循环重定向时,首先应该关注的hosts以及dns配置,确保无误. 下面记录下相关知识点: ...

  10. 【T电商 3】Nginx的Http(图片)服务器配置+ftp上传使用说明

    在前两篇博客中提到了搭建Nginx和Ftp服务器,在本篇博客,主要是介绍Nginx的配置文件的使用,怎样修改配置文件使其成为一个图片服务器. 一.Nginx图片服务器配置 <span style ...