Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

Batch file to determine latest file

Original Message
Name: ComputerRob
Date: March 18, 2008 at 16:59:55 Pacific
Subject: Batch file to determine latest file
OS: DOS 6.22
CPU/Ram: -
Model/Manufacturer: -
Comment:
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!


Report Offensive Message For Removal


Response Number 1
Name: devil_himself
Date: March 19, 2008 at 01:24:55 Pacific
Subject: Batch file to determine latest file
Reply: (edit)
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 ---


Report Offensive Follow Up For Removal

Response Number 2
Name: Mechanix2Go
Date: March 19, 2008 at 05:06:11 Pacific
Subject: Batch file to determine latest file
Reply: (edit)
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


Report Offensive Follow Up For Removal

Response Number 3
Name: Mechanix2Go
Date: March 19, 2008 at 07:00:16 Pacific
Subject: Batch file to determine latest file
Reply: (edit)
::== your.bat

@echo off

c:
cd \windows

dir /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 q

debug < some.d > nul

del list
del some.d

newexec.bat


=====================================
If at first you don't succeed, you're about average.

M2


Report Offensive Follow Up For Removal

Response Number 4
Name: ComputerRob
Date: March 19, 2008 at 09:58:03 Pacific
Subject: Batch file to determine latest file
Reply: (edit)
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.003

autoexec.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.


Report Offensive Follow Up For Removal

Response Number 5
Name: Mechanix2Go
Date: March 19, 2008 at 10:28:10 Pacific
Subject: Batch file to determine latest file
Reply: (edit)
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 off

find "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


Report Offensive Follow Up For Removal


Response Number 6
Name: ComputerRob
Date: March 19, 2008 at 10:41:18 Pacific
Subject: Batch file to determine latest file
Reply: (edit)
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


Report Offensive Follow Up For Removal

Response Number 7
Name: ComputerRob
Date: March 19, 2008 at 11:00:21 Pacific
Subject: Batch file to determine latest file
Reply: (edit)
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


Report Offensive Follow Up For Removal

Response Number 8
Name: ComputerRob
Date: March 19, 2008 at 11:28:53 Pacific
Subject: Batch file to determine latest file
Reply: (edit)
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?


Report Offensive Follow Up For Removal

Response Number 9
Name: ComputerRob
Date: March 19, 2008 at 12:02:17 Pacific
Subject: Batch file to determine latest file
Reply: (edit)
Just wondering on the your.bat above, how would I modify that so it does both the autoexec.bat and config.sys files?

Report Offensive Follow Up For Removal

Response Number 10
Name: Mechanix2Go
Date: March 19, 2008 at 12:56:41 Pacific
Subject: Batch file to determine latest file
Reply: (edit)
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


Report Offensive Follow Up For Removal

Response Number 11
Name: ComputerRob
Date: March 19, 2008 at 14:35:27 Pacific
Subject: Batch file to determine latest file
Reply: (edit)
Anybody know if there is a way to boot from a:\ but when run setup, make it think you booted from C: ??

Report Offensive Follow Up For Removal

Response Number 12
Name: Razor2.3
Date: March 19, 2008 at 17:47:53 Pacific
Subject: Batch file to determine latest file
Reply: (edit)
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.)

Report Offensive Follow Up For Removal

Response Number 13
Name: ComputerRob
Date: March 20, 2008 at 08:30:51 Pacific
Subject: Batch file to determine latest file
Reply: (edit)
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???


Report Offensive Follow Up For Removal

Response Number 14
Name: Mechanix2Go
Date: March 20, 2008 at 08:48:19 Pacific
Subject: Batch file to determine latest file
Reply: (edit)
"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


Report Offensive Follow Up For Removal

Response Number 15
Name: ComputerRob
Date: March 20, 2008 at 08:53:31 Pacific
Subject: Batch file to determine latest file
Reply: (edit)
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.

Report Offensive Follow Up For Removal

Response Number 16
Name: Mechanix2Go
Date: March 20, 2008 at 09:01:55 Pacific
Subject: Batch file to determine latest file
Reply: (edit)
Help me out here.


=====================================
If at first you don't succeed, you're about average.

M2


Report Offensive Follow Up For Removal

Response Number 17
Name: ComputerRob
Date: March 20, 2008 at 11:06:16 Pacific
Subject: Batch file to determine latest file
Reply: (edit)
DEVICE=cd1.SYS /D:banana >> c:\config.sys
MSCDEX.EXE /D:banana /L:R >> c:\autoexec.bat

The 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. ?


Report Offensive Follow Up For Removal

Response Number 18
Name: Mechanix2Go
Date: March 20, 2008 at 14:09:58 Pacific
Subject: Batch file to determine latest file
Reply: (edit)
This should do the confog.sys

::== my2.bat
:: copy latest c:\windows\config.xxx to \config.bat

@echo off

c:
cd \windows

dir /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 q

debug < some.d

newcfg.bat


=====================================
If at first you don't succeed, you're about average.

M2


Report Offensive Follow Up For Removal

Response Number 19
Name: ComputerRob
Date: March 20, 2008 at 15:16:10 Pacific
Subject: Batch file to determine latest file
Reply: (edit)
It works GREAT! Thanks for ALL your help.

Thank You Everyone.


Report Offensive Follow Up For Removal



Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Batch file to determine latest file

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software




XP Installed to G?

exessive internet traffic

ZoneAlarm Question. Blocked Connect

Windows Live Messenger Problem

Delete $Uninstall after SP3 updates


The information on Computing.Net is the opinions of its users. Such opinions may not be accurate and they are to be used at your own risk. Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE

All content ©1996-2007 Computing.Net, LLC