In [104]:
from os import walk
from os import stat

In [123]:
def get_files(mypath):
    f = []
    for (dirpath, dirnames, filenames) in walk(mypath):
        #print('Processing:', dirpath)
        for file in filenames:
            fullpath = dirpath + '/'+ file
            try:
                fdict = { 'filename': file, 'path': fullpath, 'size': (stat(fullpath)).st_size, 'modified': (stat(fullpath)).st_mtime }
                f.append(fdict)
            except:
                pass
    return f

In [124]:
files =  get_files('/')

In [125]:
def get_extensions(files):
    extensions = []
    for file in files:
        if '.' in file['filename']:
            filename_arr = (file['filename']).split('.')
            
            extension = (filename_arr[-1:])[0]
            if extension not in extensions:
                extensions.append(extension)
                
    return extensions

In [126]:
extensions = get_extensions(files)

In [ ]:


In [127]:
import random

def set_colors(extensions):
    used = []
    matched = {}
    for extension in extensions:
        r = random.randint(0,255)
        g = random.randint(0,255)
        b = random.randint(0,255)
        used.append([r,g,b])
        matched[extension] = [r,g,b]
    return matched

In [128]:
matched = set_colors(extensions)

In [ ]:


In [129]:
from PIL import Image

In [ ]:


In [130]:
#i.putpixel((0,0), (50,0,50))

columns = 800
rows = int(len(files)/columns + 1)

i = Image.new('RGB',(columns,rows), (155,155,155))

In [131]:
x = 0 
y = 0

for file in files:
    if '.' in file['filename']:
        filename_arr = (file['filename']).split('.')
        extension = (filename_arr[-1:])[0]
        rgb = (0,0,0)
        if extension in matched.keys():
            rgb = tuple(matched[extension])
            i.putpixel((x,y), rgb)
        else:
            pass
        
    else:
        pass
    
    
    x += 1
    if x > columns -1:
        y += 1
        x = 0

In [132]:
i.save('test.jpg')

In [133]:
%matplotlib inline

In [134]:
pil_im = Image.open('./test.jpg', 'r')
pil_im.show()


In [135]:
len(files)%500


Out[135]:
427

In [ ]: