接触Python编写小脚本-用来辅助项目生成

文件夹是否存在

 os.path.isdir()

获取工作路径

 os.getcwd()

定义list

 list=[]

Try语句使用

         try:
              os.remove(fullPath)
         except IOError :
              print("Try deleted file  "+i+" failed")

代码

import os, sys, shutil
path_list=os.listdir(os.getcwd())
releasePath="./Bin/Release/"
dotfuscatedPath=releasePath+"Dotfuscated/"
removeList=[]
releaseList=[]
def reMakerelease():
 print("目录为: %s"%path_list)
#1
 if os.path.isdir(releasePath):
  if os.path.isdir(dotfuscatedPath):
      for i in removeList:
          fullPath=releasePath+i
          print(fullPath)
          if os.path.isfile(fullPath):
            try:
              os.remove(fullPath)
            except IOError :
                print("Try deleted file  "+i+" failed")
                pass
          else:
              print("File "+i+" not found")
  else:
      print("Directory "+dotfuscatedPath+" not found")
 else:
     print("Directory "+releasePath+" not found")
#2
 if os.path.isdir(dotfuscatedPath):
     for i in releaseList:
         try:
           if ".exe" in i:
              shutil.copyfile(dotfuscatedPath+removeList[releaseList.index(i)],releasePath+i)
           else:
              shutil.copyfile(dotfuscatedPath+releaseList[releaseList.index(i)],releasePath+i)
         except IOError :
             print("Try Copy file  "+i+" failed")
             pass
 else:
     print("Directory "+dotfuscatedPath+" not found")

 #3
 deleteDir();
def getRemoveList():
 removeList.append("Svr.exe")
 removeList.append("Archivist.exe")
 removeList.append("Admin.exe")
 removeList.append("Client.exe")
 removeList.append("Compere.exe")
 removeList.append("Documenter.exe")
 print(removeList)
def getReleaseList():
 releaseList.append("服务器.exe")
 releaseList.append("归档查询员.exe")
 releaseList.append("管理员.exe")
 releaseList.append("客户端.exe")
 releaseList.append("会议管理员.exe")
 releaseList.append("资料员.exe")
 releaseList.append("UserControlsLB.dll")
 releaseList.append("Env.dll")
 releaseList.append("FCN.dll")
 releaseList.append("I386.dll")
 releaseList.append("LicInfo.dll")

def deleteDir():
 if os.path.isdir(dotfuscatedPath):
  shutil.rmtree(dotfuscatedPath)

def main():
    getRemoveList();
    getReleaseList();
    reMakerelease();
    print("Command executed")
    pass
if __name__ == '__main__':
    main()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值