用python删除文件

问题描述

.ck.ck-editor__top.ck-reset_all {
  z-index: var(--ck-z-modal);
  position: sticky;
  top: 0;
}

.ck.ck-sticky-panel__placeholder {
  display : none !important;
}

.ck.ck-sticky-panel .ck-sticky-panel__content_sticky {
  position: unset;
}

我想删除ro_template.bin文件。这段代码有什么问题?

解决方法

Try this:

import os
import glob
for pkg_name in glob.glob('../../pkg*'):
    if os.path.exists(pkg_name + "/dev-tools/emk-test/ro_template.bin"):
        os.remove(pkg_name + "/dev-tools/emk-test/ro_template.bin")
    else:
        print("File not found.")
,
import os
import glob
import stat
for pkg_name in glob.glob(os.path.join("..","..","pkg*")):
    file = os.path.join(pkg_name,"dev-tools","emk-test","ro_template.bin")
    if os.path.exists(file):
        try:
            os.remove(file)
        except PermissionError:
            print("chmod on permission error")
            os.chmod(file,stat.S_IWRITE)
            os.remove(file)
        break
    else:
        print("File not found.")