home *** CD-ROM | disk | FTP | other *** search
- An example batch file, RENDIR.BAT, that can be used to rename directories:
- @ECHO OFF
- REM Usage: RENDIR [d1:]pathname1 [d2:]pathname2
- REM This batch file will lose zero length files in the renamed directory!
- REM first, see if %1 is present, and is a directory,
- REM and not a root directory or disk name
- IF zip%1==zip GOTO missdir
- IF EXIST %1 GOTO notdir
- IF NOT EXIST %1\..\NUL GOTO notdir
- IF NOT EXIST %1\.\NUL GOTO notdir
- REM second, see if %2 is present, and not a file, or disk name or
- REM existing directory, or a root directory
- IF zip%2==zip GOTO missdir
- IF EXIST %2 GOTO unable
- IF EXIST %2.\NUL GOTO unable
- REM third, be sure . is not %1 or a subdirectory of it
- REM > %1\rendir$$.tst
- FOR %%x IN (. .. ..\.. ..\..\.. ..\..\..\.. ..\..\..\..\.. ..\..\..\..\..\..) DO IF EXIST %%x\rendir$$.tst GOTO isdot
- DEL %1\rendir$$.tst
- REM fourth, be sure %2 can exist
- CTTY NUL
- MKDIR %2
- IF NOT EXIST %2.\NUL GOTO twocant
- REM everything looks OK, so do it
- IF NOT EXIST %1\*.* GOTO isempty
- COPY %1\*.* %2
- FOR %%a in (%1\*.*) DO DEL %%a
- :isempty
- RMDIR %1
- CTTY CON
- IF EXIST %1\NUL ECHO Warning: Subdirectories in %1 not moved to %2
- GOTO eexxiitt
- :twocant
- CTTY CON
- :unable
- ECHO Unable to create directory
- GOTO eexxiitt
- :isdot
- IF EXIST %1\rendir$$.tst DEL %1\rendir$$.tst
- IF EXIST %1rendir$$.tst DEL %1rendir$$.tst
- :notdir
- ECHO Invalid path, not directory,
- ECHO or directory not empty
- GOTO eexxiitt
- :missdir
- ECHO Invalid number of parameters
- :eexxiitt
- EXIT