Python 에 접촉 하여 작은 스 크 립 트 작성-보조 항목 생 성

5649 단어 Python
폴 더 존재 여부
 os.path.isdir()

작업 경로 가 져 오기
 os.getcwd()

정의 목록
 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()

좋은 웹페이지 즐겨찾기