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.
attrib filename.ext -h -r -s
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.
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: