config_BK.txt
Admin.Validation/Admin.Validation.csprojBusinessObjects/CandidateManagementBO.cs BusinessObjects\EmpTempDataBO.cs BusinessObjects\JobAdBO.cs BusinessObjects\JobApplicationBO.cs BusinessObjects\PurchaseOnlineBO.cs BusinessObjects\ResumeRequestBO.cs BusinessObjects\ResumeRequestResponseBO.cs BusinessObjects\TrialEmployerBO.cs Common.Tier\EmailTemplateHelper.cs Resources\Wordings.designer.cs Resources\Wordings.resx
PythonBK.bat
@echo off
::python Python_CopyFile.py %*
Set configPath=config_BK.txt
Set sourceDir=C:\src\v8\src\
Set targetDir=D:\workspace\BKFiles\EmployerEmail\
Set isComment=False
Set isAddToday=True
python Python_CopyFile.py %configPath% %sourceDir% %targetDir% %isComment% %isAddToday%
pause & exit
config_DLL.txt
C:\src\v8\src\Core\bin\Debug\Core.dllC:\src\v8\src\Core\bin\Debug\Core.pdbC:\src\v8\src\Core\bin\Debug\Core.XMLC:\src\v8\src\Metaform\bin\Debug\Metaform.dllC:\src\v8\src\Metaform\bin\Debug\Metaform.pdbC:\src\v8\src\Resources\bin\Debug\Resources.dllC:\src\v8\src\Resources\bin\Debug\Resources.pdbC:\src\v8\src\Resources\bin\Debug\Resources.XML
config_DLL.bat
@echo off::python Python_CopyFile.py %*Set configPath=config_DLL.txtSet sourceDir=""Set targetDir=C:\src\v8\src\Web\bin\Set isComment=FalseSet isAddToday=Falsepython Python_CopyFile.py %configPath% %sourceDir% %targetDir% %isComment% %isAddToday%pause & exit
Python_CopyFile.py
#!/usr/bin/env python# -*- coding: utf-8 -*- #coding=utf-8 #copy filesimport os, sysimport shutilimport timeconfigPath = "D:\web\configBK.txt" #儲存需要拷貝的檔案路徑sourceDir = "C:\\src\\v8\\src\\" #需要拷貝的檔案的共用路徑 sourceDir為空白時表示configPath文本裡的是完整路徑targetDir = "D:\\web\\" #儲存路徑targetDir\today\...isComment = "False" #是否需要加入說明targetDir\today_說明\...isAddToday = "False" #是否需要在備份路徑中增加一個today日期的檔案夾filterFileTypes = [".csproj", ".vsmdi", ".bat"] #需要過濾的檔案類型#拷貝檔案的函數def copyFile(sourceFile, targetFile): if os.path.isfile(sourceFile): #判斷待覆制的檔案是否存在 try: ''' #方法一 index = targetFile.rfind("/") #目標路徑中最後一個/的位置 i.e. c:/path if index == -1: #如果不存在/, 那麼就是用\ i.e. c:\path ext_dir = targetFile[:targetFile.rfind("\\")] #得到檔案所在的檔案夾路徑 else: ext_dir = targetFile[:targetFile.rfind("/")] #得到檔案所在的檔案夾路徑 ''' #方法二 targetFile = targetFile.replace('\\', '/') #替換路徑中的 \ 為 / #ext_dir = os.path.dirname(targetFile) #得到檔案所在的檔案夾路徑 ext_dir = os.path.split(targetFile)[0] #os.path.split(path) 把路徑分成檔案夾路徑和檔案名稱 if not os.path.exists(ext_dir): #如果檔案夾不存在就建立檔案夾 os.makedirs(ext_dir)# else:# print(ext_dir) shutil.copy(sourceFile, targetFile) #開始拷貝檔案 print('copied ' + sourceFile + '\n') except: print('copied except from ' + sourceFile + '\nto ' + targetFile + '\n') else: print('not exists file %s' % sourceFile)#獲得所有待拷貝的檔案和目標路徑def BKFiles(configPath, sourceDir, targetDir, isComment = "False", isAddToday = "False", filterFileTypes = []): fileObject = open(configPath) #開啟存放路徑的文本 fileList = [] try: for line in fileObject: fileList.append(line.strip('\n')) #把所有路徑加入到list中,並去讀取文本行後面的符號\n finally: fileObject.close() if isAddToday == "True": today = time.strftime('%Y%m%d') #得到今天的日期 if isComment == "True": #是否需要給備份加入注釋 comment = raw_input("Enter a comment:") #提示輸入注釋 if len(comment) == 0: todayDir = targetDir + today + "\\" #產生備份檔案夾名 i.e. 20130510 else: todayDir = targetDir + today + "_" + comment + '\\' #產生備份檔案夾名 i.e. 20130510_comment else: todayDir = targetDir + today + "\\" else: todayDir = targetDir if not os.path.exists(todayDir): #如果檔案夾不存在就建立檔案夾 os.makedirs(todayDir)# print('Successful created directory') count = 0 for f in fileList: #迴圈拷貝檔案 #print("--%s--" % f) if f != "": isFilter = False for fileType in filterFileTypes: #迴圈需要過濾的檔案類型 #if f.find(fileType) > 0: #判斷檔案是否是要過濾的類型 if os.path.splitext(f)[1] == fileType: #os.path.splitext(filename) 把檔案名稱分成檔案名稱和副檔名 isFilter = True break if not isFilter: try: if sourceDir == "": copyFile(sourceDir + f, todayDir) else: copyFile(sourceDir + f, todayDir + f) count = count + 1 except: pass else: print("filtered " + f + "\n") print("copied %d file(s)\n" % count)if __name__ == "__main__": #如果不是import此python,那麼開始備份檔案 args = sys.argv[1:] if not args: print("not args") args = [configPath, sourceDir, targetDir, isComment, isAddToday] configPath = args[0] sourceDir = args[1] targetDir = args[2] isComment = args[3] isAddToday = args[4] print("Paramaters:") print("configPath:" + configPath + ".") print("sourceDir:" + sourceDir + ".") print("targetDir:" + targetDir + ".") print("isComment:" + isComment + ".") print("isAddToday:" + isAddToday + ".\n") BKFiles(configPath, sourceDir, targetDir, isComment, isAddToday, filterFileTypes)