import os, shutil

homedir = os.path.expanduser('~')
dotfileslist = os.listdir(homedir+'/dotfiles')
homelist = os.listdir(homedir)

for n in dotfileslist:

    # Move the old dotfiles
    if '.'+n in homelist:
        f_path = os.path.join(homedir, '.'+n)
        f_new_path = os.path.join(homedir, "dotfiles_old", n)
        shutil.move(f_path, f_new_path)
        print('Moved '+f_path+' to '+f_new_path)

    # Remove .git and other dotfiles
    if not (n.startswith('.')) and (n != 'installdotfiles.py'):
        f_path = os.path.join(homedir, 'dotfiles', n)
        f_sym_path = os.path.join(homedir, '.'+n)
        os.symlink(f_path, f_sym_path)
        print('Symlink '+f_path+' to '+f_sym_path)
    

