Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hello,
I find myself in the position of needing a batch file to do a specific task for a menu system I am making. What I need is this:
I have a c:\windows directory that has files such as autoexec.001, autoexec.002, etc.
I want the batch file to determine the latest file (like autoexec.003) and copy it to c:\ as autoexec.bat.
any help would be great. not working with vb or anything on this, just plain old DOS.
Thanks!

Try This
:: --- BATCH SCRIPT START ---
@echo off
setlocal
set source=c:\windows
set destdir=c:\
pushd "%source%"
for /f "tokens=*" %%a in ('dir autoexec.* /b /a-d /o:e 2^>NUL') do (set lfile=%%a)
echo copying "%source%\%lfile%" to "%destdir%" As autoexec.bat
copy /y "%source%\%lfile%" "%destdir%\autoexec.bat"
:: --- BATCH SCRIPT END ---

There is no setlocal in DOS 6.22
Do this and post result:
cd c:\windows
dir /od autoexec.*
=====================================
If at first you don't succeed, you're about average.M2

::== your.bat
@echo off
c:
cd \windowsdir /b/o-d autoexec.* > list
> some.d echo n list
>> some.d echo L 105
>> some.d echo e 100 'copy '
>> some.d echo e 111 ' \autoexec.bat'
>> some.d echo rcx
>> some.d echo 1f
>> some.d echo N newexec.bat
>> some.d echo w
>> some.d echo qdebug < some.d > nul
del list
del some.dnewexec.bat
=====================================
If at first you don't succeed, you're about average.M2

Thanks for your assistance Everyone.
I know how limiting DOS can be.Mechanix2Go, your batch file works great. My only problem now is that there is a autoexec.win in that windows directory. So the files are something like:
autoexec.win
autoexec.001
autoexec.002
autoexec.003autoexec.003 is the latest version, but if the .win is there it will use that as the latest file. .win should only be used if no .00x is present. Is there an easy fix for that? BTW what is the newexec.bat line? What is its purpose?
Also, I had one other question....
I want to some how be able to look in a batch file (autoexec.bat) see if a command (win.com) exist and if not then add it and say its been added. But if exist do nothing and say it already exist.
I messed around with the if command but its not working. I'm not sure the if command can look into a file...any ideas? If there is a better way than if that would be fine.
Any ideas??
Thanks Again for your assistance.

There is no reason that the bat would pick the .win unless it was the latest. Better take a hard look at what's in that directory.
newexec.bat is created and run by the first bat. I does the COPY.==================
As to checking for win.com, if you want it at the end, not too tough. If you want it somewhere in mid-file, things get much harder.::== chk4win.bat
@echo offfind "win.com" < autoexec.bat > nul
goto %errorlevel%:1
echo win.com >> autoexec.bat
echo added autoexec.bat
goto :eof:0
echo win.com was already there:eof
::==NOTE: I don't remember if DOS 6.22 FIND has the /i ; as written iit does a caes SENSITIVE find.
=====================================
If at first you don't succeed, you're about average.M2

Mechanix2Go,
Ok, I just tested the .win vs .003 again and you are correct it works by using the .003.
Thank You.As for the other issue....
I am getting "label not found" when running the chk4win.bat.
I did a for /? and it list the /I as "ignores the case of characters when searching for the string". So I would add the find /I to ignore case?
-Rob

I made a change to ck4win.bat which now looks to be working. It now reads:
@echo off
find "win.com" < autoexec.bat > nul
if errorlevel ==1 goto :1
if errorlevel ==0 goto :0:1
echo win.com >> autoexec.bat
echo added autoexec.bat
goto :eof:0
echo win.com was already there:eof
Thanks for your help. GREATLY APPRECIATED! Trying to remember these old commands has been fun.
Do you know of any limitations with the choice command for DOS? I used the choice command with /c:123456789 in a menu and it worked fine. But if I used a LETTTER /c:ABCDEFGHI, the darn thing would not work. I tried everyting I could think of. It would always do the wrong thing. I tried even a smaller /c:YN, even that would not work unless I changed it to /c:12.
I can't find anywhere that states it only worked with numbers. Ever heard of that?
-Rob

Sorry for the typo above... I meant:
I did a FIND /? and it list the /I as "ignores the case of characters when searching for the string". So I would add the find /I to ignore case?

Just wondering on the your.bat above, how would I modify that so it does both the autoexec.bat and config.sys files?

I don't remember ever using CHOICE in 6.22 but iin DOS 7 it's OK with letters.
I'll get to config later.
=====================================
If at first you don't succeed, you're about average.M2

Anybody know if there is a way to boot from a:\ but when run setup, make it think you booted from C: ??

No, but if you just want to use the COMMAND.COM on the C: drive, you could do something like this in your CONFIG.SYS:
shell=c:\dos\command.com
I think that's correct; DOS 6 was a long time ago. (My first PC ran DOS 6, in fact.)

Ok, Final Question here...
I still need the config.sys incorporated into the above your.bat file...
but the final question would be about the chk4win.bat above, it works great and I know he mentioned it was tougher to put command in middle of the file, but if we can't do middle, how about the beginning of the file? Any easier???

"tougher to put command in middle of the file, but if we can't do middle, how about the beginning of the file? "
USUALLY you'd want win.com at the end of the autoexec; to start windows after whatever other settings/drivers. Where else does it nned to be?
=====================================
If at first you don't succeed, you're about average.M2

Yes, I agree win.com at the end, but if I wanted to incorporate installation of cd rom drivers using same method , they need to be listed before win.com.

Help me out here.
=====================================
If at first you don't succeed, you're about average.M2

DEVICE=cd1.SYS /D:banana >> c:\config.sys
MSCDEX.EXE /D:banana /L:R >> c:\autoexec.batThe MSCDEX.exe /D:banana /L:R line in autoexec.bat need to load before win.com
But if its too involved I'll scrap that function...Would the yourbat.bat file work for the config.sys file or does it need to be modified?...when I try it it does not work. It's not putting all on same line in the new file it creates and its adding characters. ?

This should do the confog.sys
::== my2.bat
:: copy latest c:\windows\config.xxx to \config.bat@echo off
c:
cd \windowsdir /b/o-d config.* > list
> some.d echo n list
>> some.d echo L 105
>> some.d echo e 100 'copy '
>> some.d echo e 10f ' \config.sys'
>> some.d echo rcx
>> some.d echo 1b
>> some.d echo N newcfg.bat
>> some.d echo w
>> some.d echo qdebug < some.d
newcfg.bat
=====================================
If at first you don't succeed, you're about average.M2

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |