Friday, 31 July 2020

How to Make and Remove Multiple directory ?


How to make Multiple directory ?
How to remove Multiple directory ?

 Syntax    
 md    %1       end      goto       if

Description:-

md  -- Create new directory

%1 -- passing command line argument or variable

end  -- used in goto   and :end

Examples:- 

C:\md bat       c:\cd bat          c:\bat

c:\md workarea    c:\cd workarea   c:\workarea

Sample programme:-

Create directory for:- month, date, directory
31 days directory can be created in one shot bye Bat file.
Long

eg. c:\workarea\January\01

Example 1:-

@ECHO OFF
:: give file name m1.bat in notepad.exe
c:\md Main
c:\cd main
c:\main\md January
c:\main\cd january

c:\main\january\md 01
c:\main\january\md 02
c:\main\january\md 03
c:\main\january\md 04 

 :: like this upto 31 days
:end

or

Examble  2 :- 

creating directory by typing directory name in the dos prompt 

@ECHO OFF 
:: give file name m2.bat in notepad.exe

if "%1" "" goto month   
:: if %1 input not equal go to end
c:\md main
c:\cd main
c:\main\ md %1
c:\main\%1\md 01
c:\main\%1\md 02
c:\main\%1\md 03
c:\main\%1\md 04   

:: repeat  upto 31 days
:month
:: Type month  January or February or March etc
:end

More Parameters and detail description goto c:\windows\system32\md/?

Example:-
How to run  this file: keep all bat file in c:\bat

c:\bat\m2.bat january 
c:\bat\m2.bat february

or

c:\bat\m2.bat "january   01"   :: space between directory put it in quotes.
c:\bat\m2.bat "january   02"
c:\bat\m2.bat "january   03"
-----------------------


 Syntax       or
 rd
 rmdir  

Description:-

Delete a  directory   or  remove directory, 

Examples:- 

rd [<Drive>:]<Path> [/s [/q]

rmdir [<Drive>:]<Path> [/s [/q]]

or 

rd c:\main\january\01
remove date 01
or

c:\main\january\rd 01

Sample programme:-

We have created 12 month directory and 31 date directory
how to delete these diretory in one shot.

Long method of deleting directory 
eg. c:\main\January\01

First remove date -directory and then month directory

Example 1:- 

@ECHO OFF :: give file name m1.bat in notepad.exe
c:\cd main\january   
:: go to january directory

c:\main\january

c:\main\january\rd 01
c:\main\january\rd 02
c:\main\january\rd 03
c:\main\january\rd 04  
 
:: like this upto 31 days
:end

or

Example 2:- 

creating bat file by
 passing argument in Dos-prompt   

@ECHO OFF 
:: give file name m3.bat in notepad.exe It removes directory after January month

if "%1"=="" goto   month

c:\cd main\%1   :: go to january directory
c:\main\%1
pause  ::Check %1 replaced by month correct or not
c:\main\%1\rd 01
c:\main\%1\rd 02
c:\main\%1\rd 03
c:\main\%1\rd 04   :: like this upto 31 days
:month
:: Type month  January or February or March etc
:end


Example 3 :-

Example 2:- Easy way of writing above bat-file passing argument in Dos-prompt 

@ECHO OFF :: give file name m4.bat in notepad.exe
if "%1" ==  "" goto  month1  :: month1 should be with in 8 character
if "%2" ==  "" goto  date1
c:\cd main                  :: go to january directory

c:\main\%1\rd %2
c:\main\%1\rd %2
c:\main\%1\rd %2
c:\main\%1\rd %2
c:\main\%1\rd %2   :: like this upto 31 days

:mon
:: Type month  January or February or March etc
goto end  
:: this command to avoid message displaying date message
:date1
::Type date 1, 2, 3, 4, 5,6,etc
:end


Example:

c:\bat\m4.bat january 01    or   c:\bat\m4.bat january 02

No comments:

Post a Comment

HOW TO BACKUP YOUR ALL DIRECTORY IN YOUR COMPUTER AND FILE NAMES:-

HOW TO BACKUP YOUR ALL DIRECTORY IN YOUR COMPUTER AND FILE NAMES:-   Syntax         tree   /f Description:- Displays names of files in a dir...