About Cocos Creator engineering Git To configure , You can refer to :Cocos Creator engineering .gitignore Configuration of
Create a new folder , It stores multiple Cocos Creator engineering , Then put the script in this directory , Run to put all Cocos Creator All temporary documents in the project are cleared ( If the project is in use Cocos Creator open , The project needs to be shut down first )
clearCocosCreator.bat
python clearCocosCreator.py
pause
clearCocosCreator.py
import os
import shutil
dirs = ['build', 'library', 'temp', '.vscode', 'app']
files = ['.sln', '.csproj']
dirsCnt = 0
filesCnt = 0
def delWithCmd(path):
try:
if os.path.isfile(path):
cmd = 'del "'+ path + '" /F'
print(cmd)
os.system(cmd)
except Exception as e:
print(e)
def deleteDir(dirPath):
global dirsCnt
global filesCnt
for root, dirs, files in os.walk(dirPath, topdown=False):
for name in files:
try:
filesCnt += 1
filePath = os.path.join(root, name)
print('file deleted', filesCnt, filePath)
os.remove(filePath)
except Exception as e:
print(e)
delWithCmd(filePath)
for name in dirs:
try:
os.rmdir(os.path.join(root, name))
dirsCnt += 1
except Exception as e:
print(e)
os.rmdir(dirPath)
def delDir(dirPath):
global dirsCnt
shutil.rmtree(dirPath)
dirsCnt += 1
print('dir deleted', dirsCnt, dirPath)
def delFile(filePath):
global filesCnt
os.remove(filePath)
filesCnt += 1
print('file deleted', filesCnt, filePath)
def delete(path):
try:
if os.path.isfile(path):
delFile(path)
elif os.path.isdir(path):
deleteDir(path)
except Exception as e:
print(e)
for proj in os.listdir():
if not os.path.isdir(proj):
continue
os.chdir(proj)
print(os.getcwd())
for p in os.listdir():
if os.path.isdir(p) and p in dirs:
delete(p)
elif os.path.isfile(p) and os.path.splitext(p)[1] in files:
delete(p)
localPath = 'local'
if os.path.exists(localPath) and os.path.isdir(localPath):
os.chdir(localPath)
for p in os.listdir():
if p == 'local.json':
continue
delete(p)
os.chdir('..')
packagesPath = 'packages'
if os.path.exists(packagesPath) and os.path.isdir(packagesPath):
os.chdir(packagesPath)
print(os.listdir())
if os.listdir() == []:
os.chdir('..')
os.rmdir(packagesPath)
os.chdir('..')