Skip to content

Instantly share code, notes, and snippets.

@alpercalisir
Last active December 27, 2018 14:58
Show Gist options
  • Save alpercalisir/752f75781d721baf31d5741ff1824611 to your computer and use it in GitHub Desktop.
Save alpercalisir/752f75781d721baf31d5741ff1824611 to your computer and use it in GitHub Desktop.
Change the name of the sub directories such that they will be aligned with their parent directory name. Used for VGGFace 2 Dataset.
import os
import os.path
from os.path import basename
rootDir = 'img'
for dirName, subdirList, fileList in os.walk(rootDir):
#print('Found directory: %s' % dirName)
for fname in fileList:
base = basename(dirName)
location=dirName+'/'+fname
#print ('\t%s' % fname)
print(base+'_'+fname)
os.rename(dirName+"/"+fname, base+'_'+fname)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment