Example effect:
After the project is compiled and published, delete some of the configuration files and then make the compressed package that publishes the files.
#-*-coding:utf-8-*-ImportOs,sysImportZipFileImportDatetime,timedefGETTODAY_YYYYMMDD ():#return Time.strftime ("%y%m%d%h:%m:%s", Time.localtime (Time.time ())) returnTime.strftime ("%y%m%d", Time.localtime (Time.time ()))defremove_noneed_files (startdir):if(Os.path.exists (startdir+"\\appsettings.json")): Os.remove (Startdir+"\\appsettings.json") #if (os.path.exists (startdir+ "\\nlog.config")): #os.remove (startdir+ "\\nlog.config") if(Os.path.exists (startdir+"\\nlog. Development.config")): Os.remove (Startdir+"\\nlog. Development.config") #if (os.path.exists (startdir+ "\\web.config")): #os.remove (startdir+ "\\web.config")defZip_yasuo (startdir,file_news): Z= ZipFile. ZipFile (File_news,'W', ZipFile. zip_deflated) forDirpath, Dirnames, filenamesinchOs.walk (startdir): Fpath= Dirpath.replace (Startdir,"') Fpath= Fpath andFpath + os.sepor "' forFileNameinchFilenames:z.write (Os.path.join (dirpath, filename), Fpath+filename) z.close ()if __name__=="__main__": Print("Run Start") Startdir="D:\\projects\\deploy"file_news='C:\\users\admin\\desktop\\deploy'+GETTODAY_YYYYMMDD () +'. zip'remove_noneed_files (Startdir) Zip_yasuo (startdir,file_news)Print("Run finished") #os.system (' pause ')
Python to delete files and compress folders