Skip to content

Instantly share code, notes, and snippets.

@ruofeidu
Created December 13, 2017 16:16
Show Gist options
  • Save ruofeidu/1dcbb694f66c400df917f4892d1614f2 to your computer and use it in GitHub Desktop.
Save ruofeidu/1dcbb694f66c400df917f4892d1614f2 to your computer and use it in GitHub Desktop.
Batch renaming files under this script's folder
# -*- coding: utf-8 -*-
# This script renames all files under this script's folder
# Ruofei Du
# 12/13/2017
import glob, os
prefix = 'bing_'
dir_path = os.path.dirname(os.path.realpath(__file__))
sub_dir_list = glob.glob(dir_path + '*')
for dir_item in sub_dir_list:
files = glob.glob(dir_item + '/*.*')
i = 0
for f in files:
p = f.rfind('.')
extension = f[p+1:]
if extension == 'cmd' or extension == 'py' or p < 0:
continue
os.rename(f, os.path.join(prefix + str(i) + '.' + extension))
i += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment