If you use the "View" | "Thumbnails" option in your Files and
Folders windows, the hidden Thumbs.db system file in each such
folder gradually builds up (if you have not chosen "Do not cache
thumbnails" in Folder Options). To delete them you can use e.g.
following script. It has the option of bypassing the personal
photoalbums folders (mine are at C:\_H\PHOTO and its subfolders.)
@echo off & setlocal enableextensions enabledelayedexpansion
::
echo +-------------------------------------------------------+
echo ^| THUMBS.CMD Clear the hidden Thumbs.db thumbnail files ^|
echo ^| By Prof. Timo Salmi, Last modified Fri 18-Jun-2004 ^|
echo +-------------------------------------------------------+
::
:: Help wanted?
if /i [%1]==[?] goto _usage
if /i [%1]==[/?] goto _usage
::
:: Include also the photo folders into the traversing
if /i [%1]==[all] goto _all
::
:: Ask in general
set ask_=
set /p ask_="Traverse some of the hidden Thumbs.db files [y/N]?"
if /i not "%ask_%"=="y" (endlocal & goto :EOF)
::
:: Delete one by one
for /f "tokens=* delims=" %%f in (
'dir /a:h /s /b c:\Thumbs.db^|find /i /v "_h\photo\"') do (
call :DeleteOneThumb "%%f")
endlocal & goto :EOF
::
:_all
:: Ask in general
set ask_=
set /p ask_="Traverse ALL hidden Thumbs.db files [y/N]?"
if /i not "%ask_%"=="y" (endlocal & goto :EOF)
::
:: Delete one by one
for /f "tokens=* delims=" %%f in (
'dir /a:h /s /b c:\Thumbs.db') do (
call :DeleteOneThumb "%%f")
endlocal & goto :EOF
::
:_usage
echo.
echo Usage: THUMBS [all]
echo all = traverse also the c:\_h\photo folders
endlocal & goto :EOF
::
:: =============================================
:DeleteOneThumb
dir /a:h %* 2>&1 | find "1 File(s)" > nul
if %errorlevel% EQU 0 (
echo.
for /f "tokens=* delims=" %%f in (%*) do (
set fsize_=%%~zf
set fdate_=%%~tf
set fattr_=%%~af
)
echo !fdate_! !fattr_! !fsize_!
attrib -s -h %* >nul
del /p %*
attrib +s +h %* >nul)
goto :EOF
The output could be something like
C:\_D\TEST>cmdfaq
+-------------------------------------------------------+
| THUMBS.CMD Clear the hidden Thumbs.db thumbnail files |
| By Prof. Timo Salmi, Last modified Fri 18-Jun-2004 |
+-------------------------------------------------------+
Traverse some of the hidden Thumbs.db files [y/N]?y
04.01.2008 09:27 --ahs---- 4608
c:\_G\WWW\Thumbs.db, Delete (Y/N)? y
04.01.2008 08:59 --ahs---- 6144
c:\_G\WWW\FIGS\Thumbs.db, Delete (Y/N)? y
04.01.2008 09:27 --ahs---- 8704
c:\_G\WWW\ICONS\Thumbs.db, Delete (Y/N)? y
The essential trick, since the c:\Thumbs.db are hidden/system files
is to detect them. A straight dir will not do that. The /a:h (or
/a:-d or /a) switch is needed. As an aside note how the /A switch
alone can be interpreted as "ALL", undocumented by DIR /?.
The task could be also done with a single command using DEL to
traverse the disk. (See DEL /?). However, I am a bit reticent about
using such potent methods. Furthermore, the selective exclusion of
groups of files is a problem in this option. Likewise giving the
file size, file date and file attribute information prior asking for
deletion. However, if you yet want to do it relatively simply,
consider this intermediate script: