Wednesday, July 17, 2013

Why to Use Variables in Batch Files?

When you write your own batch file, you usually have no need to use  many variables in your code. Batch files with all their GOTOs and old syntax make you hard-code all needful data directly into the batch file instead of trying to make your code a bit flexible. Is this a good practice? We suppose it isn't.
Once written, code with variables can be easily copied to many different new batch scripts. Any you have no need to waste time trying to understandd your old code. Using variables makes your code much more readable and reusable, and this is the main advantage of using them.
The most useful tip is to use system variables instead of hard-coding different Windows folders. For example, it's better to use %SystemRoot% instead of writing directly "c:\Windows". You can watch all system variables by running SET command without any parameters. You can also see all actiual values of system variables in Dr.Batcher. Tools -> Environment Variables:
We kindly remind that Dr.Batcher is the best program to create batch file, both .BAT and .CMD, try it if haven't tried it yet.

Friday, July 12, 2013

Hot to Clean Thumbnail Cache

Thumbnails are the great time-savers helping us to find the needful documents (especially images) when we need them. But still thumbnails need a lot of disk space because Windows stores them in a cache in order to save time needed to generate them. And when disk space is quite law, you need to clean thumbnail cache. Here is a  simple batch file that can help you in this task:
@ECHO off
TITLE Cleaning Thumbnails...
ECHO ***This Batch File Clears The Thumbnail Cache***
ECHO Cleaning Now...
GOTO s
:s
DEL /F /Q %userprofile%\AppData\Local\Microsoft\Windows\Explorer\*.db
ECHO Thumbnail Cache Successfully Cleared!
PAUSE
We kindly remind that Dr.Batcher is the best program to create batch file, both .BAT and .CMD, try it if haven't tried it yet. 

Tuesday, July 2, 2013

Delete All Files Except Specified Ones

Sometimes it is neccessary to delete all files in a folder except some of them that are still useful. Here is small batch script that lets you delete all files except the specified ones. The parameter you pass to  this  script is the wildcard of files you want to leave.
@ECHO OFF
MD SAVE
XCOPY %1 SAVE > NUL

ECHO Y | DEL . > NUL
MOVE SAVE\*.* . > NUL
RD SAVE
ECHO Done
We kindly remind that Dr.Batcher is the best program to create batch file, both .BAT and .CMD, try it if haven't tried it yet. 

Translate