Announcement

Collapse
No announcement yet.

Delete All 'Downloads' Folder's Data

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Delete All 'Downloads' Folder's Data

    Please use the below script to clear downloaded data of all users

    Explanation:
    Script will find download folder of all users
    Deletes all files and folders of each download folder

    Code:
    import os
    uPath = 'C:\\Users'
    lDirectories = os.listdir(uPath)
    dPaths = []
    for eDir in lDirectories:
        uNPath = os.path.join(uPath, eDir)
        try:
            lSDs = os.listdir(uNPath)
            for eSD in lSDs:
                if eSD.lower() == 'downloads':
                    dPaths.append(os.path.join(uNPath, eSD))
                else:
                    continue
        except Exception:
            pass
    
    for dPath in dPaths:
        try:
            os.popen('FOR /D %p IN ("'+dPath+'\\*.*") DO rd "%p" /s /q').read()
            os.popen('del "'+dPath+'\\*" /F /Q').read()
            print(os.popen('dir "'+dPath+'"').read())
        except Exception:
            pass
    Sample Output:
    Click image for larger version

Name:	Delete All 'Downloads' Folder's Data.PNG
Views:	1
Size:	25.5 KB
ID:	4641

    Last edited by Purushothaman; 11-04-2016, 01:14 PM.
Working...
X