Ray's playground

 

Swapping One File Extension for Another Throughout a Directory Tree

Problem

You need to rename files throughout a subtree of directories, specifically changing the names of all files with a given extension so that they have a different extension instead.

Solution

Operating on all files of a whole subtree of directories is easy enough with the os.walk function from Python's standard library:

SwapExtensions

 

Usage

Before swap:

Before swap

 

Swap:

Swap

 

After swap:

After swap

 

 

posted on 2009-02-21 15:30  Ray Z  阅读(1250)  评论(0)    收藏  举报

导航