Python Forum
program wanted: clean up pyc files
Thread Rating:
  • 3 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
program wanted: clean up pyc files
#5
As mention is pretty easy to write this with os.walk().
os.walk() has also gotten a lot faster in Python 3.5-->.
scandir has been taken into standard library.
Quote:In practice, removing all those extra system calls makes os.walk() about 7-50 times as fast on Windows,
and about 3-10 times as fast on Linux and Mac OS X.
So we're not talking about micro-optimizations.
import os

source = '/foo'
for root,dirs,files in os.walk(source):
   for f_name in files:
       if f_name.endswith(('.pyc', '.txt')):
           f_name = os.path.join(root, f_name)
           print(f_name) # Test to see that's it okay first 
           #os.remove(f_name)
Reply


Messages In This Thread
program wanted: clean up pyc files - by Skaperen - Jun-13-2017, 06:08 AM
RE: program wanted: clean up pyc files - by wavic - Jun-13-2017, 06:38 AM
RE: program wanted: clean up pyc files - by Larz60+ - Jun-13-2017, 07:31 AM
RE: program wanted: clean up pyc files - by snippsat - Jun-13-2017, 05:07 PM
RE: program wanted: clean up pyc files - by nilamo - Jun-13-2017, 05:10 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  program wanted for Posix Skaperen 3 280 May-13-2024, 11:08 AM
Last Post: snippsat
  program wanted in python Skaperen 2 2,742 Aug-07-2018, 12:05 AM
Last Post: Skaperen
  program wanted: diff that ignores numbers Skaperen 0 1,945 Jun-16-2018, 02:05 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020