2

I can't recursively remove the pyc files from my Python project.

Here is the project:

    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 outputs this error:

FIND: Parameter format not correct

Anybody know how I can remove all the pyc files from this Python project?

3
  • This isn't a python problem. Please adjust the tags Commented Jul 10, 2016 at 1:08
  • I don't understand what you mean by 'please adjust the tags' - I am very new to programming and Python Commented Jul 10, 2016 at 1:13
  • The post tags on Stack Overflow Commented Jul 10, 2016 at 2:17

2 Answers 2

6

The command you're trying to use is the Linux/Unix find command, which doesn't work on Windows (unless you have something like Cygwin installed, which I don't recommend). Windows has a command with the same name, but different functionality (works more like grep). PowerShell does not have a find cmdlet or alias. You'd do recursive deletion of files with a particular extension like this in PowerShell:

Get-ChildItem -Filter '*.pyc' -Force -Recurse | Remove-Item -Force
Sign up to request clarification or add additional context in comments.

Comments

1

If the "find" command you are running is of the linux/unix equivalent, your --exec rm -rf {} will need a delimiter at the end. Like so:

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

I would also recommend always wrapping the variable brackets ({}) in quotes to ensure you are not deleting more than what you are trying to delete.

EDIT: Looks like you are using the Windows find variant, which does not support the arguments you are attempting to use. You can see this page for syntax examples.

You may want to look at one of these answers for alternatives.

2 Comments

Hi - thanks! I tried your solution and Powershell just outputted the following error: I tried wrapping the variable brackets in quotes and also tried leaving the variable brackets unwrapped by quotes. Both times Powershell outputted this error: FIND: Parameter format not correct
Thanks for the edit @Liam . I will do some research and find out how to delete all the pyc files within Powershell. It looks like I was running the "find" command that works for Bash as opposed to Powershell. If you know how to make this work in Powershell, I'd appreciate any insight you may have. Either way, thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.