import os
from subprocess import PIPE, Popen
import ctypes

class disable_file_system_redirection:
    _disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirection
    _revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirection
    def __enter__(self):
        self.old_value = ctypes.c_long()
        self.success = self._disable(ctypes.byref(self.old_value))
    def __exit__(self, type, value, traceback):
        if self.success:
            self._revert(self.old_value)
            
def ecmd(command):   
    from subprocess import Popen, PIPE
    import ctypes
    
    with disable_file_system_redirection():
        obj = Popen(command, shell = True, stdout = PIPE, stderr = PIPE)
    out, err = obj.communicate()
    ret=obj.returncode
    return ret,out,err

def User_Desktops():
    users=os.listdir("C:\\Users")
    Exception_user = ["Administrator","Default","Default User","Public","All Users"]
    fil_users=[i.strip() for i in users if i not in Exception_user]
    for i in fil_users:
        path = "C:\\Users\\%s\\Desktop"%(i)
        if os.path.exists(path):
            ret,out,err = ecmd('del /s /q /f "%s\\*.mp3"'%(path))
            if ret==0:
                print("successfully deleted mp3 files from the %s user desktop"%(i))
            else:
                print(err)
    
User_Desktops()
    
def D_drive():
    ret,out,err = ecmd("del /s /q /f D:\*.mp3")
    if ret==0:
        print('mp3 files succesfully deleted from the D drive')
    else:
        print(err)

D_drive()