N:\temp>dir Volume in drive N is HDA1_BOOT Volume Serial Number is 32FF-2953 Directory of N:\temp . <DIR> 04-17-97 3:24p . .. <DIR> 04-17-97 3:24p .. 0 file(s) 0 bytes 2 dir(s) 2,215,936 bytes free
N:\temp>+md
N:\temp>dir
Volume in drive N is HDA1_BOOT Volume Serial Number is 32FF-2953 Directory of N:\temp . <DIR> 04-17-97 3:24p . .. <DIR> 04-17-97 3:24p .. D <DIR> 04-17-97 3:24p d 0 file(s) 0 bytes 3 dir(s) 2,215,424 bytes free
N:\temp>+echo hello echo hello
Use the undocumented /R option on the VER command. C:\>ver Windows 95. [Version 4.00.950] C:\>ver /r Windows 95. [Version 4.00.950] Revision A DOS is in HMA
Use the undocumented /Z option on COMMAND N:\temp>command /z
Microsoft(R) Windows 95 (C)Copyright Microsoft Corp 1981-1995. Return code (ERRORLEVEL): 0 WARNING: Reloaded COMMAND.COM transient
N:\temp>echo test|find "test">nul Return code (ERRORLEVEL): 0
N:\temp>echo qwerty|find "test">nul Return code (ERRORLEVEL): 1
N:\temp> exit N:\temp>
This example shows how to "turn off" the serial number display for the
disk in the A: drive. The digit shown in blue on the "E" command is the
one that toggles display of the serial number.
C:\>DEBUG
-L 0 0 0 1
-E 26 00
-W 0 0 0 1
-Q
C:\>DIR A:
Volume in drive A has no label
Directory of A:\
This example shows how to set the serial number for the disk in the
A: drive to any value. Notice the numbers you enter (in red) are mirrored
from the serial number you'll get.
C:\>debug
-L 0 0 0 1
-E 26 29 78
56 34 12
-W 0 0 0 1
-Q
C:\>DIR A:
Volume in drive A has no label
Volume Serial Number is 1234-5678
Directory of A:\
|
|
E:\>copy con now.txt
Now is the time for all good men^Z 1 file(s) copied |
E:\>copy con to.txt
to come to the aid of their country^Z 1 file(s) copied |
Although my example used
type now.txt|more to.txt
the same results are achieved with
more<now.txt to.txt
H:\>attrib /s longf*.* A HR LONGFI~2.TXT H:\VB5\MSDEVE~1\Long File Name.txtThere is a temptation to use ATTRIB as a long-to-short filename converter. Unfortunately, the attributes do get displayed first. So you can't be sure what position your filename will be in because you don't know how many attributes there are. Since long file names can contain spaces, you can't just start at the end and work backwards either. The good news is that ATTRIB sets errorlevels based on whether or not it found files. So you can at least use it like a recursive IF EXIST:
attrib /s \somefile.txt if not errorlevel 1 echo I found "somefile.txt" somewhere on the disk
C:\WINDOWS>COMMAND /F
Microsoft(R) Windows 95 (C)Copyright Microsoft Corp 1981-1995.
C:\WINDOWS>DIR A:
Not ready reading drive A Abort, Retry, Fail?
Not ready reading drive A Abort, Retry, Fail?Volume in drive A has no label
Not ready reading drive A Abort, Retry, Fail?Fail on INT 24
C:\WINDOWS>if exist a:\nul echo hello
Not ready reading drive A Abort, Retry, Fail? Not ready reading drive ? Abort, Retry, Fail? C:\WINDOWS> exit
C:\WINDOWS>
echo on @if exist nul > test.txt echo offIn the above example, since NUL always exists, TEST.TXT will contain the string C:\>echo off. Although nobody does it this way, this has obvious applications in capturing prompts without launching a separate DOS shell:
@ctty nul prompt set value$Q echo on if exist nul>temp.bat hello echo off prompt $p$g ctty conWhen the above file is run, it will create a TEMP.BAT with the text set value=hello in it. The ctty nul hides the Bad command or file name error that happens because "hello" is not a valid command.
E:\>TRUENAME C:\PROGRA~1\WINZIP\..\..\WINZIP\PROGRA~1\NUL
C:/NUL
E:\>TRUENAME C:\PROGRA~1\WINZIP\..\..\WINZIP\PROGRA~1\README.TXT
C:\WINZIP\PROGRA~1\README.TXT
E:\>TRUENAME C:\PROGRA~1\WINZIP\..\WINZIP\README.TXT
C:\PROGRA~1\WINZIP\README.TXTThe bad news is that TRUENAME absolutely will not work with long file names. It simply truncates the names until they fit in an 8.3 mask, and will happily give you the bogus name as a result. The good news is that if you change into a directory, running TRUENAME without arguments will give you the real legitimate short name of the directory.
E:\>set TMP=C:\WINDOWS\TEMP TEMP=C:\WINDOWS\TEMP PROMPT=$p$g winbootdir=C:\WINDOWS COMSPEC=C:\WINDOWS\COMMAND.COM PATH=C:\WINDOWS;C:\WINDOWS\COMMAND;C:\UTILS; windir=C:\WINDOWS
E:\>command . Specified COMMAND search directory bad
Microsoft(R) Windows 95 (C)Copyright Microsoft Corp 1981-1995.
E>set PATH=
E>exit
E:\>command c:\windows
Microsoft(R) Windows 95 (C)Copyright Microsoft Corp 1981-1995.
E>set PATH=
E>exit
E:\>If you have a heavy-duty batch file, you can call it this way:
@echo off echo Here is the original environment: set echo @echo off > test.bat path >> test.bat echo echo. >> test.bat echo echo Here is the clean environment: >> test.bat echo set >> test.bat command noenvironment /c test.bat del test.bat
E:\>echo on error goto done ON E:\>echo.on error goto done on error goto done E:\>echo on E:\>echo.on on E:\>echo off - opposite of on OFF E:\>echo.off - opposite of on off - opposite of on
Running DOS 5 & 6 Under Windows 95
Now, this is the stupidest thing you could ever want to do. The only time I ever do it is when I want a quick test of some obsolete feature for a compatibility check. Otherwise I reboot my machine (I love System Commander!) into the appropriate OS. Still, to quote Douglas Adams, it's "Mostly harmless". You can see by the picture that I am running 5 different versions of DOS simultaneously. Try not to do too much unless you like seeing Incorrect DOS version on every other command. All you need to do is copy and rename your command.com files ( I picked DOS500, DOS600, etc.). Then use SETVER to put the new names in the version table, for example
setver dos500.com 5.00 setver dos600.com 6.00 setver dos620.com 6.20 setver dos622.com 6.22After you reboot, you'll be able to use the old versions of DOS simultaneously just like I do. Just don't try to run them from the command line or you'll lock up your DOS window. Either double-click them with Explorer, put them in your Start Menu, or use START from the command line to run them in a separate window.
Get Everything Before Something
Else
No, there is no better way to describe it. If you have a string like
2:34:56.78p and you want to take action based on everything before
the first colon, you can do it without parsing it character-by-character.
The only restriction is that the "colon" has to be one of these ten special
characters: [ : , . / \
; + = ] What
you do is GOTO to a label in your program and use the string as the specified
destination. Except it won't actually go there. It only reads up to the
first special character. Suppose I had these two batch files:
::TEST1.BAT
@echo off
call test2.bat 2:34:56.78p
::TEST2.BAT
@echo off
goto LBL%1
:LBL
echo I didn't go to a label!
goto DONE
:LBL1
echo At label 1
goto DONE
:LBL2
echo At label 2
goto DONE
:DONE
When TEST1 runs, it calls TEST2, passing it 2:34:56.78p as
an argument. TEST2 then has a GOTO command which you might think would
get interpreted as GOTO LBL2:34:56.78p The amazing thing
is that it actually goes to LBL2! Everything from the colon
on to the right got ignored! So this is a way to make a jump in your program
based on a drive letter, hour, month or who knows what else.
Lost? Look at the site map.
Bad links? Questions? Send me mail.