In Windows, it is eay to copy / duplicate the entire directory tree by simply right click the mouse. But, how to mould / copy only the directory tree structure ? This batch file is the answer.
The following batch file named tree_mould.bat can mould / copy the directory tree structure without copying the files inside. It can be used in the command line mode or inside the GUI explorer (by using the Send To).
The batch file will by default mould / copy the directory tree structure to a new directory name with the current date as suffix. So, your PC has to pre-set the short date format as YYYY-MM-DD in order for this batch file proper functioning.
Here is the batch file tree_mould.bat
@echo off :: ------------------------------------------------------ :: Licence Information: :: -------------------- :: This coding is offered at no charge for :: NON-COMMERCIAL PERSONAL USE only. :: The coding is copyright. :: Reproduction of this coding in whole or in part :: in any form without the express written permission :: of the author is strictly prohibited. :: ------------------------------------------------------ :: Disclaimer: :: ----------- :: This coding is distributed "as is" and is UNSUPPORTED. :: NO WARRANTY of any kind is expressed or implied. :: You use AT YOUR OWN RISK. :: The author will not be liable for any data loss, :: damages, and loss of profits or any other kind of :: tangible or intangible loss while using or :: misusing this coding. :: ------------------------------------------------------ :: Name : tree_mould.bat :: Purpose : Mould the directory tree using the xcopy command :: with today as the suffix of the new tree :: Platform: DOS, Win XP :: Author : Alvin SIU :: Date : 2007-12-16 :: ------------------------------------------------------ :: Attentions: :: ----------- :: 1. It is highly recommended to set the SHORT date format :: of your PC to be YYYY-MM-DD :: 2. If your short date format uses slash (i.e. /) as :: separator, this batch file cannot function properly. :: ------------------------------------------------------ :: Command Line Usage Example: :: tree_mould A_Directory :: This will mould the directory tree structure of :: A_Directory to A_Directory.d2007-12-16 :: provided that today is 2007-12-16 and the date /t command :: in your PC will display 2007-12-16 :: ------------------------------------------------------ :: GUI Installation: :: 1. Put this file tree_mould.bat into any directory :: 2. Go to your Send To folder :: 3. Create a shortcut tree_mould.bat to point to this file :: GUI Usage Example: :: 1. Highlight any one directory, e.g. A_Directory :: 2. Right click mouse :: 3. Select Send To :: 4. Select the shortcut tree_mould.bat :: This will mould the directory tree structure of :: A_Directory to A_Directory.d2007-12-16 :: provided that today is 2007-12-16 and the date command :: in your PC will display 2007-12-16 :: ------------------------------------------------------ set TMP_TREE_MOULD_NEW_DIR=%1.d%DATE% echo tree_mould echo from tree : %1 echo to tree : %TMP_TREE_MOULD_NEW_DIR% echo. if not exist %1 goto NOT_EXIST if not exist %1\NUL goto NOT_DIR if exist %TMP_TREE_MOULD_NEW_DIR% goto JUST_EXIST mkdir %TMP_TREE_MOULD_NEW_DIR% if errorlevel 1 goto MD_ERR xcopy /f /t /e %1 %TMP_TREE_MOULD_NEW_DIR% if errorlevel 1 goto XCOPY_ERR echo OK, directory tree structure is moulded goto QUITING :NOT_EXIST echo ERROR: There is no such directory %1 goto QUITING :NOT_DIR echo ERROR: The item %1 echo ERROR: is NOT a directory goto QUITING :JUST_EXIST echo ERROR: Target directory %TMP_TREE_MOULD_NEW_DIR% echo ERROR: already exist goto QUITING :MD_ERR echo Error: Cannot Create NEW directory %TMP_TREE_MOULD_NEW_DIR% goto QUITING :XCOPY_ERR echo ERROR: xcopy returns error goto QUITING :QUITING set TMP_TREE_MOULD_NEW_DIR= echo. echo. pause :: ------------------------------------------------------ :: End Of File tree_mould.bat :: ------------------------------------------------------ |
The detail installation and usage instruction are at the beginning of the file.
Alvin SIU2008-12-16
Copyright/Licence Information: All information and coding in this article is offered at no charge for NON-COMMERCIAL PERSONAL USE only. This blog and the coding is copyright. Reproduction of this blog and its coding in whole or in part in paper or digitally or in any other forms without the explicit written permission of the author is strictly prohibited. |
Disclaimer: All information in this article is distributed "as is" and is UNSUPPORTED. NO WARRANTY of any kind is expressed or implied. You use AT YOUR OWN RISK. The author will not be liable for any data loss, damages, and loss of profits or any other kind of tangible or intangible loss while using or misusing wholly or partly of the information. |