Reputation: 53
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?
Upvotes: 2
Views: 2078
Reputation: 200523
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
Upvotes: 6
Reputation: 2001
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.
Upvotes: 1