Removing .pyc files from under current directory (Python CLI)


>>> for dirpath, subdirs, files in os.walk("."):
...  for f in files:
...   if "pyc" in f:
...    print(os.path.join(dirpath, f))
...
.\scraping\api\__pycache__\api_endpoints.cpython-37.pyc
.\scraping\api\__pycache__\__init__.cpython-37.pyc
.\scraping\config\__pycache__\config.cpython-37.pyc
.\scraping\services\spiders\__pycache__\__init__.cpython-35.pyc
.\scraping\services\spiders\__pycache__\__init__.cpython-37.pyc
.\scraping\services\__pycache__\crawl_service.cpython-37.pyc
.\scraping\services\__pycache__\middlewares.cpython-35.pyc
.\scraping\services\__pycache__\middlewares.cpython-37.pyc
.\scraping\services\__pycache__\pipelines.cpython-37.pyc
.\scraping\services\__pycache__\settings.cpython-35.pyc
.\scraping\services\__pycache__\settings.cpython-37.pyc
.\scraping\services\__pycache__\__init__.cpython-35.pyc
.\scraping\services\__pycache__\__init__.cpython-37.pyc
.\scraping\test\__pycache__\conftest.cpython-37-pytest-5.2.1.pyc
.\scraping\test\__pycache__\test_api.cpython-37-pytest-5.2.1.pyc
.\scraping\test\__pycache__\test_config.cpython-37-pytest-5.2.1.pyc
.\scraping\test\__pycache__\test_swagger.cpython-37-pytest-5.2.1.pyc
.\swagger\api\__pycache__\api_endpoints.cpython-37.pyc
.\swagger\api\__pycache__\api_endpoints.cpython-38.pyc
.\swagger\api\__pycache__\__init__.cpython-37.pyc
.\swagger\api\__pycache__\__init__.cpython-38.pyc
.\swagger\config\__pycache__\config.cpython-37.pyc
.\swagger\config\__pycache__\config.cpython-38.pyc
.\swagger\config\__pycache__\__init__.cpython-37.pyc
.\swagger\config\__pycache__\__init__.cpython-38.pyc
.\swagger\services\spiders\__pycache__\__init__.cpython-35.pyc
.\swagger\services\spiders\__pycache__\__init__.cpython-37.pyc
.\swagger\services\spiders\__pycache__\__init__.cpython-38.pyc
.\swagger\services\__pycache__\crawl_service.cpython-37.pyc
.\swagger\services\__pycache__\middlewares.cpython-35.pyc
.\swagger\services\__pycache__\middlewares.cpython-37.pyc
.\swagger\services\__pycache__\pipelines.cpython-37.pyc
.\swagger\services\__pycache__\settings.cpython-35.pyc
.\swagger\services\__pycache__\settings.cpython-37.pyc
.\swagger\services\__pycache__\__init__.cpython-35.pyc
.\swagger\services\__pycache__\__init__.cpython-37.pyc
.\swagger\services\__pycache__\__init__.cpython-38.pyc
.\swagger\test\__pycache__\conftest.cpython-37-pytest-5.2.1.pyc
.\swagger\test\__pycache__\test_api.cpython-37-pytest-5.2.1.pyc
.\swagger\test\__pycache__\test_config.cpython-37-pytest-5.2.1.pyc
.\swagger\test\__pycache__\test_swagger.cpython-37-pytest-5.2.1.pyc

>>> for dirpath, subdirs, files in os.walk("."):
...  for f in files:
...   if "pyc" in f:
...    os.remove(os.path.join(dirpath, f))
...

>>> for dirpath, subdirs, files in os.walk("."):
...  for f in files:
...   if "pyc" in f:
...    print(os.path.join(dirpath, f))
...
>>>


No comments:

Post a Comment