Showing posts with label folders. Show all posts
Showing posts with label folders. Show all posts

Tuesday, September 3, 2013

Using PUSHD and POPD Commands in Batch Files

There are two really handy commands that are not very commonly used by the batch files' developers. They are named PUSHD and POPD. If you are familiar with Assembler, you may guess what these commands do. The first one stores the folder name (pushes directory) in some internal stack, and the second one brings it back (pops directory). Note that you can put several folders to the stack and them restore them in the reversed order (LIFO - last in, first out). It is much handier sometimes to use PUSHD/POPD instead of using special variables to store folders like in other programming languages.
Here's small example of using these commands:
ECHO Performing some file manipulations in one directory
REM Here are manipulations
REM Remembering this folder
PUSHD
CD AnotherFolder
ECHO Performing some file manipulations in another directory
REM Here are manipulations
REM Remembering this folder
PUSHD
CD YetAnotherFolder
ECHO Performing some file manipulations in this directory
REM Here are manipulations
REM Deleting temporary files in YetAnotherFolder
POPD
REM Deleting temporary files in AnotherFolder
POPD
REM Deleting temporary files in the first folder
REM That's all
So you should remember about these commands while you create batch files.
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. 

Thursday, June 27, 2013

Batch File to Calculate Disk Space

If you need to calculate disk space used by a directory or by some files, the batch file below can be useful for you. If you call it with the parameter /d it lists each subdirectory. Without any parameters it just prints the total number of files and bytes.
@echo off
if not '%1=='/d goto howmuch1
dir /a-d /s|find "i"|find /v "Volume"|more
goto done
:howmuch1
dir /a-d /s|find "file(s)"|sort /r|find /n "f"|find "[1]"

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. 

Wednesday, May 29, 2013

Calculate Folder Size in Batch File

It is neccessary sometimes to calculate the size of a certain folder in batch file. Though it is easy to see the size of a folder in Windows, calculating it in a batch script can be considered quite a complicated task. This small script will help you with this task:
@Echo Off
For /F "Tokens=3*" %%a In (
'Dir /-C C:\Temp ^| Find "files"') Do Echo The C:\Temp folder size = %%a
pause
Of course you should first change 'c:\Temp' to path to the folder which size you want to calculate.
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