home *** CD-ROM | disk | FTP | other *** search
- echo off
- echo.
- echo ┌───────────────────────────────────────────────────┐
- echo │ Directory with sort and generalized name matching │
- echo │ By Prof. Timo Salmi, ts@chyde.uwasa.fi, 9-Jul-91 │
- echo └───────────────────────────────────────────────────┘
- echo.
-
- rem If no parameters are given to the batch, then display help
- if "%1"=="" goto _help
-
- rem Check that a (ram)disk exists on r:
- if not exist r:\nul goto _err1
-
- rem Make the searchstring uppercase
- set _tmp=%path%
- path %1
- set _upcase=%path%
- path %_tmp%
-
- rem Make a temporary directory
- dir *.* > r:\d.tmp
-
- rem Read the switches
- set _n=
- set _e=
- set _s=
- set _r=
- :_loop
- shift
- if "%1"=="" goto _sort_1
- if "%1"=="/n" set _n=yes
- if "%1"=="/N" set _n=yes
- if "%1"=="/e" set _e=yes
- if "%1"=="/E" set _e=yes
- if "%1"=="/s" set _s=yes
- if "%1"=="/S" set _s=yes
- if "%1"=="/r" set _r=/r
- if "%1"=="/R" set _r=/r
- goto _loop
-
- rem The sorting routines
- :_sort_1
- if "%_n%"=="yes" goto _sort_n
- :_sort_2
- if "%_e%"=="yes" goto _sort_e
- :_sort_3
- if "%_s%"=="yes" goto _sort_s
- :_sort_4
- goto _display
-
- :_sort_n
- sort %_r% < r:\d.tmp > r:\tmp$$$.$$$
- copy r:\tmp$$$.$$$ r:\d.tmp > nul
- del r:\tmp$$$.$$$
- goto _sort_2
-
- :_sort_e
- sort %_r% /+10 < r:\d.tmp > r:\tmp$$$.$$$
- copy r:\tmp$$$.$$$ r:\d.tmp > nul
- del r:\tmp$$$.$$$
- goto _sort_3
-
- :_sort_s
- sort %_r% /+14 < r:\d.tmp > r:\tmp$$$.$$$
- copy r:\tmp$$$.$$$ r:\d.tmp > nul
- del r:\tmp$$$.$$$
- goto _sort_4
-
- rem Find the entries containing the searchstring
- :_display
- find "%_upcase%" r:\d.tmp | more
- goto _out
-
- :_help
- echo D is a DIR command enhancement. It uses a generalized searchstring which is
- echo matched with the file name REGARDLESS of the location of the string within
- echo the file name. Wildcards (* and ?) should not be used. They are implicit.
- echo.
- echo Usage: D SearchString [/n] [/e] [/s] [/r]
- echo │ │ │ └─ Reverse the sort
- echo │ │ └─ Sort by size
- echo │ └─ Sort by extension
- echo └─ Sort by name
- echo.
- echo Examples: D bat /s /r (all batch files sorted from biggest to smallest)
- echo D - /n (to see the entire sorted directory (- or . or /) )
- echo D j (all file names having a J in them, unsorted)
- echo D /r (error in logic, no sort key has been defined)
- echo.
- echo If you get an "Out of environment space" message, increase your environment
- echo space by using shell configuration in config.sys apply the following MsDos
- echo 3.30 example: shell=c:\bin\command.com /e:1024 /p
- goto _out
-
- :_err1
- echo D.BAT assumes by default a (ram)disk in drive R. You do not have that
- echo drive is available, and you should substitute r:\d.bat throughout the
- echo batch as relevant for your own configuration. (Using a ramdisk is
- echo advisable, because potential read-only problems are avoided.)
-
- :_out
- if exist r:\d.tmp del r:\d.tmp
- set _tmp=
- set _upcase=
- set _n=
- set _e=
- set _s=
- set _r=
- echo on
-