powershell - 无法从 Python 项目中递归删除 pyc 文件

标签 powershell recursion pyc

我无法递归地从我的 Python 项目中删除 pyc 文件。

这是项目:

    Directory: C:\Users\jk025523\projects\ex47


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       10/07/2016     01:52                bin
d-----       10/07/2016     01:52                docs
d-----       10/07/2016     01:52                ex47
d-----       10/07/2016     01:52                tests
-a----       09/07/2016     21:02            521 setup.py

There are indeed some pyc files inside the tests directory:

    Directory: C:\Users\jk025523\projects\ex47\tests


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----       09/07/2016     21:28            180 ex47_tests.py
-a----       09/07/2016     21:28            721 NAME_tests.pyc
-a----       05/07/2016     10:52              0 __init__.py
-a----       05/07/2016     11:37            140 __init__.pyc

However when I enter this command in PowerShell to remove all the pyc files:

find . -name "*.pyc" -exec rm -rf {}

PowerShell 输出此错误:

FIND: Parameter format not correct

有人知道如何从这个 Python 项目中删除所有 pyc 文件吗?

最佳答案

您尝试使用的命令是 Linux/Unix find命令,它在 Windows 上不起作用(除非你安装了类似 Cygwin 的东西,我不推荐这样做)。 Windows 有一个 command with the same name ,但功能不同(更像 grep)。 PowerShell 没有 find cmdlet 或别名。您将在 PowerShell 中递归删除具有特定扩展名的文件:

Get-ChildItem -Filter '*.pyc' -Force -Recurse | Remove-Item -Force

关于powershell - 无法从 Python 项目中递归删除 pyc 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38287651/

相关文章:

sql-server - 如何使用 PowerShell 监控进程的 CPU 使用率?

powershell - 从 AzureAD/Office 365 清除已删除的外部用户失败并出现 UserNotFoundException

powershell - Set-StrictMode 不涵盖整个 PowerShell 脚本

AZ 存储 Blob 上的 Azure CLI IF 存在结果

c# - 异步递归方法

python - 共享/备份时使用 .py 或 .pyc 文件?

python - 在生产中禁用 pyc 文件

python - 我如何理解 .pyc 文件内容

python - 如何在 python 中递归创建排列列表?

python - 这个函数即使不调用自身也是递归的吗?