2

I am looking for a free program that automatically removes all the useless hidden files from a selected USB drive.

The files I'm talking about are the ones like .Trashes, etc... (essentially all the ones that start with . (a period/full-stop).

Requirements:

  • free
  • runs on Windows 7 64 bit (and OSX 10.6.8 if possible)
  • 2
    for OS X, already inlcuded. The Terminal.app and remove the files with bash script. Or, use AppleScript or Automator.app workflow. – jm666 Jul 18 '14 at 21:51
  • 1
    What makes you think that every file starting with . is "useless". Some may be, but the origin of this naming is with Unix, where files which were important to system stability were so named. They wouldn't show up on a normal directory listing so that well meaning newbies wouldn't "tidy" them and destabilize the system. You might want to rethink a blanket approach to such files. – Mawg Mar 10 '15 at 9:07
  • 1
    @Mawg You're right, but my use case was for removing files from a USB drive, and I'll never have any system files on my USB, therefore this will work for me. Anything starting with a period, to me, on my USB, is useless! – ᔕᖺᘎᕊ Mar 10 '15 at 17:18
4

You can use the following Python script to remove every file and folder starting with .. Install Python, cd to the root of your USB key and type python hidden_file_remover.py:

# Save this script as hidden_file_remover.py in the root of your USB key:
import os
import shutil
import sys    

def main(folder_path):
    for dirpath, dirnames, filenames in os.walk(folder_path):
        for dirname in [d for d in dirnames if (d.startswith("."))]:
            dirfullpath = os.path.join(dirpath, dirname)
            print dirfullpath
            try:
                shutil.rmtree(dirfullpath)
            except:
                pass

    for dirpath, dirnames, filenames in os.walk(folder_path):     
        for filename in [f for f in filenames if (f.startswith("."))]:
            filepath = os.path.join(dirpath, filename)
            print filepath
            os.remove(filepath)                

if __name__ == "__main__":
    try:
        folder_path = str(sys.argv[1])
    except:
        folder_path = "default_folder_path"
    main(folder_path)
3

7zip can be more helpful. Although it is a compression tool there is an inbuilt explorer (far better than the Windows 7 one) in 7zip which can be used as another way to view/remove hidden files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.