Script to Search and Remove All Hidden Folders

Last update on November 8, 2009 10:12 AM by jak58
Published by jak58

Script to Search and Remove All Hidden Folders




Issue



I need a Script (VB or BAT : Prefferebly BAT Script) That will search and delete all Files and Folders (Even the folders that contain subfolders and files) which has Hidden Attribute
in a particular drive or folder. That is the script, when run, will search for all files and folders in a drive and will delete all the files and folders which are hidden but will not affect of delete files which are not hidden.

I actually want this for getting rid of some nasty redundant virus which comes via USB drives and memory cards. Usually they don't show up in the explorer and I have to manually delete them from command line by changing their attributes.


The commands:

attrib filename.ext -h -r -s 

then del 

del filename.ext 



What i want actually is getting some script to make the process simpler for ignorant people here in my office who unknowingly infect the computers by running the virus codes. The antivirus does not helps much. I am planning to make an exe out of that batch script and add that in the Right Click Context Menu of Drives and Folders. I don't care if other important files with Hidden Attribute gets deleted in this procedure because Usually the Source are Memory cards and the files that are needed are only Image Files which are not hidden and therefore would not be affected by this procedure. Also if some filter can be created for certain extensions like jpeg,raw etc for not to be deleted, it would be better.

Please help me out.

Solution


To Delete whole tree you can use this:

FOR /F "tokens=*" %%G IN ('DIR /B /AD /S *.gif*') DO RMDIR /S /Q %%G 



DIR /B /AD /S *.gif*
lists all files that are named ".gif"
/B makes the output "bare" with nothing but the file name
/AD only lists directories
/S recurses subdirectories to include their contents if they match the listing criteria


RMDIR /S /Q [path/name]
deletes the directory [path/dir] and all of it's children

FOR /F processes each item (in this case directories) in the set IN ('[command]') by executing the DO [command]

%%G is a parameter, which in this example is a directory name
"tokens=*" says that all the characters output in a line (i.e. by the dir command) are assigned to the parameter %%G

For the Hidden files selection you can refer the Microsoft Command Line Reference (below link) for more on FOR:

http://technet.microsoft.com/en-au/library/bb491071.aspx

In addition these are my tips for Hidden files operation, compile yourself and try:

XCOPY /H copies the files, including the hidden files to a new destination

DEL /A-H deletes non-hidden files from the new folder

DEL /AH deletes hidden files from the original folder

Note


Thanks to Aadhi for this tip on the forum.
Best answers for « Script to Search and Remove All Hidden Folders » in :
The option to display hidden files and folders has disappeared ShowThe option to display hidden files and folders has disappeared Under Windows XP, you may lose the options that allows you to view files and cookies. This is usually due to changes in the register caused by a virus or malicious software on...
How to remove "NewFolder.exe" virus? ShowHow to remove "NewFolder.exe" virus? Issue Solution Issue Newfolder.exe is a virus (Malicious folder) which real name is Iddono, appear everywhere in your hard-drive. Once it is executed, some malicious process will be started like...
MacOS X: Delete obstinate Files ShowMacOS X: Delete obstinate Files It may happens sometimes when trying to empty the recycle bin and that the files or folders you want to delete it still refuses to disappear. To resolve this problem, use a UNIX command in Terminal....
Download WinMend Folder Hidden ShowDescription The application is designed by WinMend.com. WinMend Folder Hidden is a tool that allows you to hide folders quickly. Simple and easy to use, the application has been awarded from various places. Offering an intuitive interface, the...
Operating Systems - MS-DOS - Tips ShowSetting the CD-ROM drive The CD-ROM drive is configured in the config.sys and autoexec.bat system files. The CD-ROM drive device driver must be configured in the config.sys file (even if the device is automatically detected in Windows). To do...
Linux - The shell ShowIntroduction to the shell The command interpreter is the interface between the user and the operating system, hence the name "shell". The shell therefore acts as an intermediary between the operating system and the user thanks to command lines...