Created
December 13, 2017 16:16
-
-
Save ruofeidu/1dcbb694f66c400df917f4892d1614f2 to your computer and use it in GitHub Desktop.
Batch renaming files under this script's folder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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