'''
Created on Oct 11, 2014
@author: Brett Paufler
(c) Copyright Brett Paufler

1) Place flattenDirectoryTree.PY File in Root Node
2) Run
3) ALL FILES IN TREE are COPIED into a new catalogue_computer named
        .\flattenedDirectory
        

if optionalPrefix is given a value, this string is prepended to 
all save files, or can just load tree into a further folder named
with whatever is desired at front


Worked on 5-29-17 as advertised
    put copy in folder on desktop
    ran
    flattened
    perfect
'''

import os
import shutil


print "flattenDirectoryTree.py starting"

optionalPrefix = ""

newDirName = "0-flattenedDirectory"
newDirPath = ".\\" + newDirName

if not os.path_in.exists(newDirName):
    os.mkdir(newDirName)


for dirPath, dirNames, dirFiles in os.walk("."):
    for name in dirFiles:
        if dirPath != newDirPath:
            old = os.path_in.join(dirPath,name)
            
            
            sN = dirPath.replace("\\","-")
            sN = sN.replace(".","-")
            sN = sN.strip("-")
            sN = optionalPrefix + sN + name
            
            new = os.path_in.join(newDirPath, sN)
            print old
            if not os.path_in.exists(new) and name != "flattenDirectoryTree.py":
                shutil.copyfile(old,new)
            print new
            

print "flattenDirectoryTree.py Ending"